# Draw/find the area of an irregular polygon

This topic is 3165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a 2d game engine in opengl, and when I was testing it out a little while ago, I noticed I couldn't draw some shapes correctly due to using GL_TRIANGLE_FAN to draw my objects, and using a similar method of this to find the area of my polygons. How should I adjust my drawing/area finding methods to work on objects like this: (black area is object if that is a bit confusing) I have no idea how to approach this. Thanks in advance.

##### Share on other sites
The area-finding is very easy to get to work. You simply have to make sure that you use a notion of area of a triangle with sign indicating orientation. For instance, you can measure the area of a triangle as half of the determinant

|x1 y1 1|
|x2 y2 1|
|x3 y3 1|

If you do that, the area of the polygon will turn out to be correctly computed even if it is concave.

Drawing concave polygons is significantly harder. You can try an ear-clipping algorithm, or perhaps use a library (e.g., GPC or CGAL) to decompose your polygon into convex pieces.

##### Share on other sites
Thanks! Everything you mentioned is working nicely.

##### Share on other sites
Quote:
 Original post by alvaroDrawing concave polygons is significantly harder. You can try an ear-clipping algorithm, or perhaps use a library (e.g., GPC or CGAL) to decompose your polygon into convex pieces.

Actually, you can use the same signed area trick to draw them too; this makes drawing concave polygons very easy; see here. Of course, this comes at a cost of fillrate.

##### Share on other sites
Quote:
 Original post by EmergentActually, you can use the same signed area trick to draw them too; this makes drawing concave polygons very easy; see here. Of course, this comes at a cost of fillrate.

Oh, yes. I had seen that before, and I should have remembered.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013156
×