Hi,

I'd like to compute the intersection between a plane and a 3D object composed of triangles. Then I'd like to draw this intersection contour.

Seemed easy enough at the start. I started by computing plane/edge line segment intersection. This gives me the contour points, but there's no guarantee on the ordering for resulting polygon.

For example one of the corner cases is a square composed of 2 triangles that's right on the plane:

{(0,0), (1,0), (0, 1)}, {(0,1), (1,0), (1,1)}

Straight line segment intersection gives me the right points, but the order of those points is all wrong - I can't draw them using GL_LINE_STRIP for example and get a contour of a square.

I could try sorting the result points in CCW order. However the result polygon can also be concave.

Another corner case is branching. For example taking an intersection through a shape that looks like this ---V V----

would produce 2 separate contour polygons.

Any suggestions on an algorithm(s) I can use?