# Given two non-intersecting polygons, how to determine which one is in front

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. • Maybe I am misunderstanding something, but neither should be "in front" if they are coplanar, right? May 26, 2022 at 14:27
• the vertices of each polygon are coplanar with each other. Between polygons, the only assumption is that they are not intersecting but need not be coplanar May 26, 2022 at 14:29
• If the vertices are coplanar then the polygons are also coplanar. So I don't think there's one "in front". May 26, 2022 at 17:36
• the vertices of one polygon are not coplanar with the vertices of another polygon May 26, 2022 at 18:41
• In that case you can intersect the two polygons. If they are not coplanar then this will give you two cases: a no intersection case, and an intersection case. You know how to deal with the former, for the latter you'll have to split the polygons along their intersection, resulting in 4 pieces. You can order these pieces since they are disjoint. May 26, 2022 at 20:00