R3.Geometry.Euclidean3D.DistancePointPlane C# (CSharp) Method

DistancePointPlane() public static method

public static DistancePointPlane ( Vector3D normalVector, Vector3D planePoint, Vector3D point ) : double
normalVector Vector3D
planePoint Vector3D
point Vector3D
return 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();
        }

Usage Example

Example #1
0
        /// <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));
            }
        }
All Usage Examples Of R3.Geometry.Euclidean3D::DistancePointPlane