<p>I'm dealing with hardware that uses quads as its polygonal primitive. Not triangles. A triangle can be expressed by setting 2 of the 4 vertices equal to each other for a degenerate quad.</p>

<p>For the 3D engine, I'm in need of clipping for polygons outside of clip space volume in order to avoid vertex inversion and division by zero errors when performing the perspective divide.</p>

<p>My logic is that I first identify the primitives that intersect with the 6 planes. From there I add edges to cut the primitive. What I don't understand at this point is how to cut/add quads. Do I need to "triangulate", but for quads? Is it possible? Are there constraints other than the quad needing to be convex?</p>

<p>Edit: I might be over complicating this. I can't come up with a case where I get less than 4 or more than 4 vertices when clipping. The only case is when all points are outside the clipping area, all except one edge. That edge would produce a triangle.</p>

CC BY-SA 3.0
2017-07-29T14:33:41.383Z
What about when 2 vertices are outside the clipping area and the other 2 are inside? You can end up with a pentagon or hexagon inside. Or when 2 are outside one corner and the other 2 are outside the opposite corner?
user1118321
CC BY-SA 3.0
2017-07-29T20:42:38.913Z
Good point... I guess I have to cover these edge cases.
mrkotfw
CC BY-SA 3.0
2017-08-01T13:45:28.613Z
@user1118321 although if you do the planes one by one you will just split the original quad and have a standard solution again.
joojaa
CC BY-SA 3.0
2017-08-03T01:12:35.420Z
@joojaa I'm not sure what you mean. What do you mean by standard solution?
mrkotfw
<3d><algorithm><geometry><mathematics><clipping>
Algorithm for clipping convex quadrilaterals
mrkotfw
# Algorithm for clipping convex quadrilaterals

(Asked by: username_0 on 2017-07-29)

I'm dealing with hardware that uses quads as its polygonal primitive. Not triangles. A triangle can be expressed by setting 2 of the 4 vertices equal to each other for a degenerate quad.

For the 3D engine, I'm in need of clipping for polygons outside of clip space volume in order to avoid vertex inversion and division by zero errors when performing the perspective divide.

My logic is that I first identify the primitives that intersect with the 6 planes. From there I add edges to cut the primitive. What I don't understand at this point is how to cut/add quads. Do I need to "triangulate", but for quads? Is it possible? Are there constraints other than the quad needing to be convex?

Edit: I might be over complicating this. I can't come up with a case where I get less than 4 or more than 4 vertices when clipping. The only case is when all points are outside the clipping area, all except one edge. That edge would produce a triangle.

**Tags:** 3d, algorithm, geometry, mathematics, clipping

> **Comments:**
> **username_1**: What about when 2 vertices are outside the clipping area and the other 2 are inside? You can end up with a pentagon or hexagon inside. Or when 2 are outside one corner and the other 2 are outside the opposite corner?  
> **username_0**: Good point... I guess I have to cover these edge cases.  
> **username_2**: @username_1 although if you do the planes one by one you will just split the original quad and have a standard solution again.  
> **username_0**: @username_2 I'm not sure what you mean. What do you mean by standard solution?  

---

## 0 answers

