Example #1
0
        /// <summary>
        /// Computes a geodesic on a mesh given a starting point and an initial direction.
        /// Returns true if successfull and false if something went wrong.
        /// </summary>
        public static bool StartDir(HE_MeshPoint meshPoint, Vector3d vector, HE_Mesh mesh, int maxIter, out List <Point3d> geodesic)
        {
            // Get initial face on the mesh
            HE_Face initialFace = mesh.Faces[meshPoint.FaceIndex];
            // Start iteration

            // Create variables for current iteration step
            HE_Face  thisFace      = initialFace;
            Point3d  thisPoint     = new Point3d();
            Vector3d thisDirection = vector;

            int            iter       = 0;
            List <Point3d> geodPoints = new List <Point3d>();

            do
            {
                Ray ray = new Ray(thisPoint, thisDirection);

                // Find intersection between ray and boundary
                AR_Lib.Intersect3D.RayFacePerimeter(ray, thisFace, out Point3d nextPoint, out HE_HalfEdge halfEdge);

                // Intersection method should check for correct direction using sign of dot product

                // Add point to pointlist
                geodPoints.Add(nextPoint);

                // Walk to next face
                HE_Face nextFace = halfEdge.Twin.Face;

                // Flip vector to next face
                Vector3d perpVector = Vector3d.CrossProduct(thisDirection, HE_MeshGeometry.FaceNormal(thisFace));
                Vector3d nextVector = Vector3d.CrossProduct(HE_MeshGeometry.FaceNormal(nextFace), perpVector);

                // Assign iteration variables to current
                thisPoint     = nextPoint;
                thisFace      = nextFace;
                thisDirection = nextVector;

                // Increase counter
                iter++;
            } while (iter < maxIter);

            // Assign outputs
            geodesic = geodPoints;
            return(true);
        }
Example #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></returns>
        public static ISRayFacePerimeter RayFacePerimeter(Ray ray, HE_Face Face, out Point3d result, out HE_HalfEdge halfEdge)
        {
            Vector3d faceNormal = HE_MeshGeometry.FaceNormal(Face);
            Vector3d biNormal   = Vector3d.CrossProduct(ray.Direction, faceNormal);

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

            List <HE_Vertex> 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);
            }
        }