Beispiel #1
0
        /// <summary>
        /// Get the intersection between a line and a plane.
        //  If the line and plane are not parallel, the function outputs true, otherwise false.
        /// </summary>
        /// <param name="intersection"></param>
        /// <param name="ray"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        public static bool LinePlaneIntersection(out Vector3 intersection, Ray ray, ExtPlane plane)
        {
            float   length;
            float   dotNumerator;
            float   dotDenominator;
            Vector3 vector;

            intersection = Vector3.zero;

            //calculate the distance between the linePoint and the line-plane intersection point
            dotNumerator   = Vector3.Dot((plane.Point - ray.origin), plane.Normal);
            dotDenominator = Vector3.Dot(ray.direction, plane.Normal);

            //line and plane are not parallel
            if (dotDenominator != 0.0f)
            {
                length = dotNumerator / dotDenominator;

                //create a vector from the linePoint to the intersection point
                vector = ExtVector3.SetVectorLength(ray.direction, length);

                //get the coordinates of the line-plane intersection point
                intersection = ray.origin + vector;

                return(true);
            }

            //output not valid
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        //This function returns a point which is a projection from a point to a plane.
        public static Vector3 ProjectPointInPlaneMethod2(Vector3 planeNormal, Vector3 planePoint, Vector3 point)
        {
            float   distance;
            Vector3 translationVector;

            //First calculate the distance from the point to the plane:
            distance = SignedDistancePlanePoint(planeNormal, planePoint, point);

            //Reverse the sign of the distance
            distance *= -1;

            //Get a translation vector
            translationVector = ExtVector3.SetVectorLength(planeNormal, distance);

            //Translate the point to form a projection
            return(point + translationVector);
        }