/// <summary>
/// Reflect a point in us.
/// </summary>
public Vector3D ReflectPoint(Vector3D p)
{
if (IsPlane)
{
// We used to call ProjectOntoPlane, but optimized it away.
// This is faster because we already know our normal is normalized,
// and it avoids some extra Vector3D operations.
double dist = Euclidean3D.DistancePointPlane(this.Normal, this.Offset, p);
Vector3D offset = this.Normal * dist * -2;
return(p + offset);
}
else
{
if (p == Center)
{
return(Infinity.InfinityVector);
}
if (Infinity.IsInfinite(p))
{
return(Center);
}
Vector3D v = p - Center;
double d = v.Abs();
v.Normalize();
return(Center + v * (Radius * Radius / d));
}
}