1

Given a triangulated mesh (no self intersection, no holes, possibly concave) represented as an unordered list of triangles (list of 3 vertices) or rectangles (list of 4 vertices), i.e.

[
    [[x1, y1], [x2, y2], [x3, y3]],
    [[x4, y4], [x5, y5], [x6, y6], [x7, y7],
    ....
]

How can I sort the vertices in a clockwise order?

Rufus
  • 5,111
  • 4
  • 28
  • 45

1 Answers1

0

You can sort by angle.

There are different implementations, like you can use atan2() in C++ to calculate the angle of each vertex and sort them along.

In case they have same angle, you can sort them by distance to the origin to break tie.

Community
  • 1
  • 1
shole
  • 4,046
  • 2
  • 29
  • 69