Skip to content

Commit d39eb3a

Browse files
committed
Fix super triangle creation in 3D space
1 parent cadce6f commit d39eb3a

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/ObjObject.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static Face[] BowyerWatson(Vertex[] vertices)
225225
private static Face FindSuperTriangle(Vertex[] vertices)
226226
{
227227
// Setup super triangle.
228-
double minX, maxX, dX, midX, minY, maxY, dY, midY, minZ, maxZ, dZ, midZ;
228+
double minX, maxX, minY, maxY, minZ, maxZ;
229229

230230
minX = minY = minZ = Double.MaxValue;
231231
maxX = maxY = maxZ = Double.MinValue;
@@ -248,25 +248,23 @@ private static Face FindSuperTriangle(Vertex[] vertices)
248248
maxZ = v.Z;
249249
}
250250

251-
double d = 10;
251+
ClippingPlane plane = new ClippingPlane(vertices[0], vertices[1], vertices[2]);
252252

253-
maxX += d;
254-
maxY += d;
255-
maxZ += d;
256-
minX -= d;
257-
minY -= d;
258-
minZ -= d;
259-
253+
Vertex a = new Vertex(minX, minY, minZ);
254+
Vertex b = new Vertex(maxX, maxY, maxZ);
260255

261-
dX = maxX - minX;
262-
dY = maxY - minY;
263-
dZ = maxZ - minZ;
256+
Vector ab = (Vector)(b - a);
257+
a -= 10*ab;
258+
b += 10*ab;
264259

265-
midX = dX / 2 + minX;
266-
midY = dY / 2 + minY;
267-
midZ = dZ / 2 + minZ;
260+
Vector triBase = Vector.CrossProduct(ab, plane.Normal).Unit();
268261

269-
return new Face(new Vertex(minX, minY, minZ), new Vertex(midX, maxY, minZ), new Vertex(maxX, minY, minZ));
262+
double length = ((Vector)(b - a)).Length();
263+
264+
Vertex c = a + triBase * length;
265+
Vertex d = a - triBase * length;
266+
267+
return new Face(b, c, d);
270268
}
271269

272270
// Checks if a point lies in the circumsphere of a face.

0 commit comments

Comments
 (0)