public static DistancePointPlane ( Vector3D normalVector, Vector3D planePoint, Vector3D point ) : double | ||
normalVector | Vector3D | |
planePoint | Vector3D | |
point | Vector3D | |
리턴 | double |
public static double DistancePointPlane( Vector3D normalVector, Vector3D planePoint, Vector3D point )
{
// Check to make sure that plane is not degenerate.
if( Tolerance.Zero( normalVector.MagSquared() ) )
return double.NaN;
// Here is the distance (signed depending on which side of the plane we are on).
return ( point - planePoint ).Dot( normalVector ) / normalVector.Abs();
}
/// <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)); } }