public virtual Vector3d Project(Vector3d vPoint, int identifier = -1) { int tNearestID = Spatial.FindNearestTriangle(vPoint); var triangle = new Triangle3d(); Mesh.GetTriVertices(tNearestID, ref triangle.V0, ref triangle.V1, ref triangle.V2); Vector3d nearPt, bary; DistPoint3Triangle3.DistanceSqr(ref vPoint, ref triangle, out nearPt, out bary); return(nearPt); }
/// <summary> /// Find distance from point to mesh /// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame. /// </summary> public static double NearestPointDistance(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint, double maxDist = double.MaxValue) { int tid = spatial.FindNearestTriangle(queryPoint, maxDist); if (tid == DMesh3.InvalidID) { return(double.MaxValue); } Triangle3d tri = new Triangle3d(); mesh.GetTriVertices(tid, ref tri.V0, ref tri.V1, ref tri.V2); Vector3d closest, bary; double dist_sqr = DistPoint3Triangle3.DistanceSqr(ref queryPoint, ref tri, out closest, out bary); return(Math.Sqrt(dist_sqr)); }