Triangulate a polygon in C#

Triangulating a polygon means breaking it into triangles. This is easy for simply shapes such as rectangles. It's even easy for convex polygons. It's more interesting for non-convex polygons.

To triangulate a polygon, first define an ear to be a corner of a polygon that sticks out. More rigorously, three adjacent vertexes form an ear if the angle they form is convex and the triangle they form does not contain any of the polygon's other points. It can be shown that any polygon with more than three points has at least two ears.

The method used by this program is:

    Do While (# vertices > 3)
Find an ear.
Add the ear to the triangle list.
Remove the ear's middle vertex from the polygon.
Loop
Make a triangle from the 3 remaining vertices.

For a nice, detailed explanation of this method, see Ian Garton's Web page.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.