Ejemplo n.º 1
0
        /// <summary>
        /// Compute the intersection between a mesh face perimeter and a ray tangent to the face.
        /// </summary>
        /// <param name="ray">The tangent ray.</param>
        /// <param name="face">The mesh face.</param>
        /// <param name="result">The resulting intersection point.</param>
        /// <param name="halfEdge">The half-edge on where the intersection lies.</param>
        /// <returns>Intersection result.</returns>
        public static ISRayFacePerimeter RayFacePerimeter(Ray ray, MeshFace face, out Point3d result, out MeshHalfEdge halfEdge)
        {
            Vector3d faceNormal = MeshGeometry.FaceNormal(face);
            Vector3d biNormal   = Vector3d.CrossProduct(ray.Direction, faceNormal);

            Plane perpPlane = new Plane(ray.Origin, ray.Direction, faceNormal, biNormal);

            List <MeshVertex> vertices = face.AdjacentVertices();

            Point3d temp = new Point3d();

            Line line = new Line(vertices[0], vertices[1]);

            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result   = null;
                halfEdge = null;
                return(ISRayFacePerimeter.Point);
            } // No intersection found

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(ISRayFacePerimeter.Point);
            } // Intersection found

            line = new Line(vertices[1], vertices[2]);
            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result   = null;
                halfEdge = null;
                return(ISRayFacePerimeter.NoIntersection);
            } // No intersection found

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(ISRayFacePerimeter.Point);
            } // Intersection found

            line = new Line(vertices[2], vertices[0]);
            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result   = null;
                halfEdge = null;
                return(ISRayFacePerimeter.NoIntersection);
            }

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(ISRayFacePerimeter.Point);
            }
            else
            {
                result   = null;
                halfEdge = null;
                return(ISRayFacePerimeter.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Compute the intersection between a mesh face perimeter and a ray tangent to the face.
        /// </summary>
        /// <param name="ray">The tangent ray.</param>
        /// <param name="face">The mesh face.</param>
        /// <param name="result">The resulting intersection point.</param>
        /// <param name="halfEdge">The half-edge on where the intersection lies.</param>
        /// <returns>Intersection result.</returns>
        public static RayFacePerimeterIntersectionStatus RayFacePerimeter(
            Ray ray,
            MeshFace face,
            out Point3d result,
            out MeshHalfEdge halfEdge)
        {
            var faceNormal = MeshGeometry.FaceNormal(face);
            var biNormal   = Vector3d.CrossProduct(ray.Direction, faceNormal);

            var perpPlane = new Plane(ray.Origin, ray.Direction, faceNormal, biNormal);

            var vertices = face.AdjacentVertices();

            var temp = new Point3d();

            var line = new Line(vertices[0], vertices[1]);

            if (LinePlane(line, perpPlane, out temp) != LinePlaneIntersectionStatus.Point)
            {
                result   = null;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.Point);
            } // No intersection found

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.Point);
            } // Intersection found

            line = new Line(vertices[1], vertices[2]);
            if (LinePlane(line, perpPlane, out temp) != LinePlaneIntersectionStatus.Point)
            {
                result   = null;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.NoIntersection);
            }

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.Point);
            }

            line = new Line(vertices[2], vertices[0]);
            if (LinePlane(line, perpPlane, out temp) != LinePlaneIntersectionStatus.Point)
            {
                result   = null;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.NoIntersection);
            }

            if (temp != ray.Origin && temp != null)
            {
                result   = temp;
                halfEdge = null;
                return(RayFacePerimeterIntersectionStatus.Point);
            }

            result   = null;
            halfEdge = null;
            return(RayFacePerimeterIntersectionStatus.Error);
        }