1
$\begingroup$

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.

enter image description here

$\endgroup$
5
  • $\begingroup$ Maybe I am misunderstanding something, but neither should be "in front" if they are coplanar, right? $\endgroup$
    – lightxbulb
    May 26, 2022 at 14:27
  • $\begingroup$ 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 $\endgroup$
    – Vince W.
    May 26, 2022 at 14:29
  • $\begingroup$ If the vertices are coplanar then the polygons are also coplanar. So I don't think there's one "in front". $\endgroup$
    – lightxbulb
    May 26, 2022 at 17:36
  • $\begingroup$ the vertices of one polygon are not coplanar with the vertices of another polygon $\endgroup$
    – Vince W.
    May 26, 2022 at 18:41
  • 1
    $\begingroup$ 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. $\endgroup$
    – lightxbulb
    May 26, 2022 at 20:00

2 Answers 2

1
$\begingroup$

You could implement a Z buffer. That is, just start drawing the polygons in any order and in a separate buffer record the pixels depth in the scene (0.0 - 1.0 ranging from the front viewing plane to the rear viewing plane of the frustum) Then when you render the next polygon, compare its depth with that existing in the buffer. If the depth is less (closer to the viewer) draw the pixel, and if it is equal to or greater keep the pixel that already exists in the image.

$\endgroup$
1
  • $\begingroup$ Thank you for the reply. My ultimate goal is not to render them but actually to get the visible polygons as a new set of polygons. So basically I have to determine which polygon is on front so that I can perform a clipping operation to get the new polygons that are visible $\endgroup$
    – Vince W.
    Jun 10, 2022 at 11:43
0
$\begingroup$

It sounds to me that maybe you need to have a look at Newell, Newell,& Sancha's algorithm ( Paper from 1972 or Wikipedia Summary ). It was a method to order polygons into back to front order so that you could use a "Painters' Algorithm" to do hidden surface removal (back when a Z-buffer would have probably cost more than a house).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.