Jump to content
  • Advertisement
Sign in to follow this  
jeff0

OpenGL Connected lines 2 polygon algorithm?

This topic is 4400 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

Hullo! I've been working on an algorithm for converting a series of connected lines, or vertices, into a triangular patch. If the connected lines define a convex region this is relatively simple to do but it's quite complex when it comes to non-convex thingies. I've managed to create something that works quite well, but it's kind of slow... it involves starting with two vertices and testing which third vertex will make a triangle not overlapping any already created triangle that is still inside the original body being converted, this is repeated until a good match is found. I also use some basic culling so that vertices which cannot be part of any new triangle are removed from the list of vertices being concidered. Anyway, I was wondering if there is a well-known algorithm for building a non-overlapping triangular mesh from a set of lines, or if there is perhaps some better approach I can use instead... i.e. rendering polygons with OpenGL. I tried rendering my lines as polygonal patches in OpenGL but it didn't work and I've read that GL_POLYGON only supports convex polygons. Maybe there is a way to easily divide a non-convex polygon into convex sub-polygons?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The GLU has a tesselation thingy that will convert con-convex polygons for you.

Share this post


Link to post
Share on other sites
The operation you're talking about is called Triangulation. If you look for papers about it you'll find that easily coded algorithms typically run in O(n^2) where n is the number of vertices. Good (hard to code) algorithms run in O(nlogn) or o(nlogn), and there is one theoretical algorithm (impossible to code) that runs in O(n).

One algorithm that I have coded, which is fairly robust keeps a linked list of vertices that surround the untriangulated region (so it starts off containing all of the vertices of the polygon in the order which they surround the region). Then you take three adjacent vertices and check that the triangle they form is valid (contains no other vertices in the set). If that triangle is invalid, you move forward one and try the next three adjacent vertices, if the triangle is valid, you add it to the triangle list, and remove the middle of the three vertices from the untriangulated region list. Stop when you have only three vertices left in the linked list (don't forget to add that triangle though).

This algorithm runs in O(n^2), but has very low overhead, and is very very easy to code.

Good luck!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!