I have two 3D polygons, and in both of them all vertices are coplanar. I set a viewing direction and transform the polygons into the coordinate system of the viewing direction, such that the x, y components of the vertices are the projection into the orthographic viewing plane and the z component is the distance from the plane. What I want to do now is to create the set of 2d polygons that outline all of the visible surfaces. To do this I take the difference of the front polygon from the one in back, resulting in just that portion of the back polygon that is visible.
The part that I am stuck on is how do I determine which polygon is in front? There are simple cases where all of the z-values in one will be greater than the z-values in the other, but there will be more complicated cases where the z-extents of both overlap. I imagine this must be known, but I am having trouble finding the answer.