Compute the Cross Section of a Cube

algorithm, sorting

Solution

the intersection is a convex polygon, so any sorting that works for convex polygons will work here as well.

In particular:

- calculate the centroid Z = (A+B+C+...) / numPoints

- calculate the normal n = AB cross BC

- get the Vector from the centroid to the first point: ZA

- order all points P by the signed angle ZA to ZP with normal n (signed angle == angle(ZA,ZP) * sign (n dot (ZA cross ZP) )

Problem

As is indicated in the following images, the cross section of a cube can be: - Triangle - Rectangle - Pentagon (NOT DREW) - Hexagon Assume that we are getting a hexagon. We can get the intersection points of the cross plane with each side of the cube and get the hexagon `ABCDEF`. The question is: how do we sort the intersection points so that the hexagon `ABCDEF` can be divided into 4 triangles `ABC`, `ACD`, `ADE` and `AEF`. Notice that the order of the points is very important because if I get the order wrong, I won't be able to draw it out. I want to divide them into triangles because I want to visualized them in OpenGL. Thanks so much for @HugoRune's answer. Here some result that I want to share with you guys. Left image is the cross section of a 3D volume (from an arbitrary angle). Right image is the result of maximum intensity projection of the 3D volume.

Original source

Related problems