2

I need to find all vertices that makes my surface, but I only know vertices (keep them as array) and edges. I'm doing it in XY coordinate system. I need it for Unity3D project (so pseudocode or C# code will be very helpful), but any mathematic ideas are appreciated, too.

I made some pictures for example. If I don't have convex angle in my example it's really easy - I choose any vertex (e.g. 0) and take two next vertex in the loop. It gaves me triangles 0-1-2, 0-2-3 and 0-3-4. enter image description here

It's quite easy, too, if I have one convex angle. I don't know how to find which vertex is convex (any ideas?) but it doesn't seem very complicated. Then I take him and make the same algorithm as above. enter image description here

Unfortunatelly my idea stopped work for more complicated shapes, e.g (I always have one shape in my project, I just draw more of them to show more complex examples): enter image description here

If I have shapes like this and try to use method described above, always any triangle is out of my shape.

I think that I can use for that any mathematic. My vertices are on XY coordinates, so I can count something. I can make more vertices if I need, too, so I could have: enter image description here

I was trying to describe my problem as exactly how I can. I hope my english is understable.

Please, if you have any ideas - math ideas or pseudocode ideas how to make a surface for my vertices - write. If you have any single suggestion, not concrete idea - write, too. I am looking for inspiration, ideas, anything.

Queen
  • 173
  • 1
  • 11
  • 1
    Mixing up convex and concave I think? – Raimund Krämer Oct 27 '17 at 11:21
  • yes, convex and concave angles are my problem – Queen Oct 27 '17 at 11:24
  • 2
    I mean I think you mixed up the terms in your explaination. Convex ones shouldn't really be the problem, as you described above, but referring to them as concave. – Raimund Krämer Oct 27 '17 at 11:26
  • Hm, when I think about angles I think about them: https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/22815495_10214283491339230_2820980967849292174_n.jpg?oh=83e7cec9888c55587ec2be7cd4e86016&oe=5A66BD1D And I think they're my problem. – Queen Oct 27 '17 at 11:37
  • 3
    google **triangulation** ... like **Ear clipping** ... – Spektre Oct 27 '17 at 11:43
  • 1
    This was an active area of research in the 80s and 90s in finite element automatic meshing. Search for quadtree, automatic meshing, etc. to find what the latest is. – duffymo Oct 27 '17 at 11:56
  • 1
    Possible duplicate of [Convert polygon to triangles](https://stackoverflow.com/questions/7316000/convert-polygon-to-triangles) – Arman Papikyan Oct 27 '17 at 12:16
  • Please complete the expected research before posting here. – Prune Oct 27 '17 at 16:51

1 Answers1

0

I'll make two assumptions:

  • You don't have any particular standards of one triangulation being better than another.
  • You want something conceptually easy.

Pick any vertex. Connect to any other vertex such that the formed line is entirely within the polygon. This means

  • The other vertex is not adjacent to the original
  • the connecting segment doesn't cross a side of the polygon.

It's possible that there is no such vertex. If so, then move to the next vertex, iterating until you find a pair you can connect. There will be at least one such pair.

When you draw that new segment, you've also divided the polygon into two polygons, each of which has fewer vertices than the original.

Recur on each of these polygons. Your stopping case (base case) on each thread is that you don't divide a triangle.

Prune
  • 76,765
  • 14
  • 60
  • 81