// Aka Jarvis march public static List <Vector3D> GiftWrappingXZ(List <Vector3D> positions) { // Find leftmost point int leftMostPoint = 0; for (int i = 1; i < positions.Count; i++) { if (positions[i].x < positions[leftMostPoint].x) { leftMostPoint = i; } } int pointOnHull = leftMostPoint; int endPoint = 0; List <Vector3D> res = new List <Vector3D>(); do { res.Add(positions[pointOnHull]); endPoint = pointOnHull == 0?1:0; for (int j = 0; j < positions.Count; j++) { if (j != pointOnHull && HMeshMath.LeftOfXZ(positions[pointOnHull], positions[endPoint], positions[j])) { endPoint = j; } } pointOnHull = endPoint; } while (endPoint != leftMostPoint); return(res); }
static bool IsLocalDelaunay(Halfedge e) { if (e.IsBoundary()) { return(true); } Vector3 p1 = e.vert.position; Vector3 p2 = e.next.vert.position; Vector3 p3 = e.next.next.vert.position; Vector3 p4 = e.opp.next.vert.position; return(HMeshMath.InCircle(p1, p2, p3, p4) || HMeshMath.InCircle(p2, p1, p4, p2)); }
static Face FindTriangleWithinPoint(HMesh mesh, Vector3 pos) { foreach (var face in mesh.GetFaces()) { var edges = face.Circulate(); var p1 = edges[0].vert.position; var p2 = edges[1].vert.position; var p3 = edges[2].vert.position; Debug.LogWarning("Points " + p1 + ", " + p2 + ", " + p3); if (HMeshMath.LeftOf(p1, p2, pos) && HMeshMath.LeftOf(p2, p3, pos) && HMeshMath.LeftOf(p3, p1, pos)) { return(face); } } Debug.LogWarning("Cannot find triangle"); return(null); }
static bool IsLocalDelaunay(Halfedge e) { if (e.IsBoundary()) { return(true); } var p1 = e.vert.positionD; var p2 = e.next.vert.positionD; var p3 = e.next.next.vert.positionD; var p4 = e.opp.next.vert.positionD; if (projectPlane == ProjectionPlane.XZ) { return(HMeshMath.InCircleXZ(p1, p2, p3, p4) || HMeshMath.InCircleXZ(p3, p1, p4, p2)); } else { Debug.LogError("Not implemented"); return(false); } }
static bool IsPointInTriangle(Face face, Vector3D pos) { var edges = face.Circulate(); var p1 = edges[0].vert.positionD; var p2 = edges[1].vert.positionD; var p3 = edges[2].vert.positionD; if (projectPlane == ProjectionPlane.XZ) { if (HMeshMath.RightOfXZ(p1, p2, pos) && HMeshMath.RightOfXZ(p2, p3, pos) && HMeshMath.RightOfXZ(p3, p1, pos)) { return(true); } } else { Debug.LogError("Not implemented"); } return(false); }
public static List <Vector3D> AklToussaintHeuristic(List <Vector3D> positions) { int maxX = 0, maxY = 0, minX = 0, minY = 0; for (int i = 0; i < positions.Count; i++) { if (positions[i].x < positions[minX].x) { minX = i; } if (positions[i].x > positions[maxX].x) { maxX = i; } if (positions[i].y < positions[minY].y) { minY = i; } if (positions[i].y > positions[maxY].y) { maxY = i; } } List <int> points = new List <int>(); points.Add(minX); if (!points.Contains(minY)) { points.Add(minY); } if (!points.Contains(maxX)) { points.Add(maxX); } if (!points.Contains(maxY)) { points.Add(maxY); } if (points.Count <= 2) { return(positions); } /*Gizmos.color = Color.green; * for (int i=0;i<points.Count;i++){ * Gizmos.DrawLine((positions[points[i]]+Vector3D.one*0.01f).ToVector3(), (positions[points[(i+1)%points.Count]]+Vector3D.one*0.01f).ToVector3()); * }*/ List <Vector3D> res = new List <Vector3D>(); for (int i = 0; i < positions.Count; i++) { if (points.Contains(i)) { res.Add(positions[i]); } else { bool inside = true; for (int j = 0; j < points.Count && inside; j++) { inside = HMeshMath.LeftOfXY(positions[points[j]], positions[points[(j + 1) % points.Count]], positions[i]); } if (!inside) { res.Add(positions[i]); } } } return(res); }