Jump to content
  • Advertisement
Sign in to follow this  
logank9

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by alvaro
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by Emergent
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.


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!