<p>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.</p>

CC BY-SA 4.0
2022-06-10T11:43:16.310Z
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
Vince W.
CC BY-SA 4.0
2022-06-09T17:30:01.080Z
2022-06-09T17:30:01.080Z
Gabriel Rohweder
<p>It sounds to me that maybe you need to have a look at Newell, Newell,&amp; Sancha's algorithm ( <a href="https://ohiostate.pressbooks.pub/app/uploads/sites/45/2017/09/newell-newell-sancha.pdf" rel="nofollow noreferrer">Paper from 1972</a> or <a href="https://en.wikipedia.org/wiki/Newell%27s_algorithm" rel="nofollow noreferrer">Wikipedia Summary</a> ).  It was a method to order polygons into back to front order so that you could use a &quot;Painters' Algorithm&quot; to do hidden surface removal (back when a Z-buffer would have probably cost more than a house).</p>

CC BY-SA 4.0
2022-06-10T08:03:10.060Z
2022-06-10T08:03:10.060Z
Simon F
<p>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.</p>
<p>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.</p>
<p><a href="https://i.sstatic.net/ZzXaZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZzXaZ.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-05-26T14:27:33.317Z
Maybe I am misunderstanding something, but neither should be "in front" if they are coplanar, right?
lightxbulb
CC BY-SA 4.0
2022-05-26T14:29:46.070Z
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
Vince W.
CC BY-SA 4.0
2022-05-26T17:36:01.550Z
If the vertices are coplanar then the polygons are also coplanar. So I don't think there's one "in front".
lightxbulb
CC BY-SA 4.0
2022-05-26T18:41:42.247Z
the vertices of one polygon are not coplanar with the vertices of another polygon
Vince W.
CC BY-SA 4.0
2022-05-26T20:00:47.970Z
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.
lightxbulb
<computational-geometry><polygon>
Given two non-intersecting polygons, how to determine which one is in front
Vince W.
# Given two non-intersecting polygons, how to determine which one is in front

(Asked by: username_0 on 2022-05-26)

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](https://i.sstatic.net/ZzXaZ.png)](https://i.sstatic.net/ZzXaZ.png)

**Tags:** computational-geometry, polygon

> **Comments:**
> **username_1**: Maybe I am misunderstanding something, but neither should be "in front" if they are coplanar, right?  
> **username_0**: 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  
> **username_1**: If the vertices are coplanar then the polygons are also coplanar. So I don't think there's one "in front".  
> **username_0**: the vertices of one polygon are not coplanar with the vertices of another polygon  
> **username_1**: 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.  

---

## 2 answers

### Answer by username_2 on 2022-06-09. Score: 1

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.

> **Comments:**
> **username_0**: 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  

---

### Answer by username_3 on 2022-06-10. Score: 0

It sounds to me that maybe you need to have a look at Newell, Newell,& Sancha's algorithm ( [Paper from 1972](https://ohiostate.pressbooks.pub/app/uploads/sites/45/2017/09/newell-newell-sancha.pdf) or [Wikipedia Summary](https://en.wikipedia.org/wiki/Newell%27s_algorithm) ). 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).


---

