Beispiel #1
0
        /// <summary>
        /// Tests for intersection between a <see cref="Segment"/> and a <see cref="Plane"/>.
        /// </summary>
        /// <param name="line">A <see cref="Segment"/> instance.</param>
        /// <param name="plane">A <see cref="Plane"/> instance.</param>
        /// <returns><see langword="true"/> if intersection occurs; otherwise, <see langword="false"/>.</returns>
        public static bool TestIntersection(Segment segment, Plane plane)
        {
            // Get the position of the line's end point relative to the plane.
            int sign0 = (int)plane.GetSign(segment.P0);
            int sign1 = (int)plane.GetSign(segment.P1);

            // Intersection occurs if the 2 endpoints are at oposite sides of the plane.
            return(((sign0 > 0) && (sign1 < 0)) || ((sign0 < 0) && (sign0 > 0)));
        }
Beispiel #2
0
        /// <summary>
        /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Plane"/>.
        /// </summary>
        /// <param name="ray">A <see cref="Ray"/> instance.</param>
        /// <param name="plane">A <see cref="Plane"/> instance.</param>
        /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
        public static IntersectionPair Intersects(Ray ray, Plane plane)
        {
            bool     intersect   = false;
            Vector3F hitPoint    = Vector3F.Zero;
            float    denominator = Vector3F.Dot(plane.Normal, ray.Direction);

            // Check if the ray is parrallel to the plane
            if (MathFunctions.ApproxEquals(denominator, 0.0f))
            {
                // If the line is parallel to the plane it only intersects the plane if it is on the plane.
                intersect = (plane.GetSign(ray.Origin) == MathFunctions.Sign.Zero);
                if (intersect)
                {
                    hitPoint = ray.Origin;
                }
            }
            else
            {
                float t = (plane.Constant - Vector3F.Dot(plane.Normal, ray.Origin)) / denominator;
                hitPoint  = ray.Origin + ray.Direction * t;
                intersect = true;
            }

            return(new IntersectionPair(intersect, hitPoint));
        }
        /// <summary>
        /// Tests for intersection between a <see cref="Segment"/> and a <see cref="Plane"/>.
        /// </summary>
        /// <param name="line">A <see cref="Segment"/> instance.</param>
        /// <param name="plane">A <see cref="Plane"/> instance.</param>
        /// <returns><see langword="true"/> if intersection occurs; otherwise, <see langword="false"/>.</returns>
        public static bool TestIntersection(Segment segment, Plane plane)
        {
            // Get the position of the line's end point relative to the plane.
            int sign0 = (int)plane.GetSign(segment.P0);
            int sign1 = (int)plane.GetSign(segment.P1);

            // Intersection occurs if the 2 endpoints are at oposite sides of the plane.
            return ( ((sign0 > 0) && (sign1 < 0)) || ((sign0 < 0) && (sign0 > 0)) );
        }
        /// <summary>
        /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Plane"/>.
        /// </summary>
        /// <param name="ray">A <see cref="Ray"/> instance.</param>
        /// <param name="plane">A <see cref="Plane"/> instance.</param>
        /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
        public static IntersectionPair Intersects(Ray ray, Plane plane)
        {
            bool intersect = false;
            Vector3F hitPoint = Vector3F.Zero;
            float denominator = Vector3F.Dot(plane.Normal, ray.Direction);

            // Check if the ray is parrallel to the plane
            if (MathFunctions.ApproxEquals(denominator, 0.0f))
            {
                // If the line is parallel to the plane it only intersects the plane if it is on the plane.
                intersect = (plane.GetSign(ray.Origin) == MathFunctions.Sign.Zero);
                if (intersect)
                    hitPoint = ray.Origin;
            }
            else
            {
                float t = (plane.Constant - Vector3F.Dot(plane.Normal, ray.Origin)) / denominator;
                hitPoint = ray.Origin + ray.Direction * t;
                intersect = true;
            }

            return new IntersectionPair(intersect, hitPoint);
        }