Reputation: 443
I have a list of vertices in 3d, in random order. I need to construct a polygon from them.
I've found a solution for this in 2d, that uses polar coordinates: ordering shuffled points that can be joined to form a polygon (in python)
It calculates the center of the shape, then arranges the vertices by polar coordinate. Problem is, in 3d there are 2 angles involved, if I use spherical coordinates. How do I sort my list of vertices in case of sphereical coordinates?
Upvotes: 1
Views: 971
Reputation: 16906
Are the points lying on a plane? First find the center, then use a vector cross product on the relative positions of a couple randomly chosen points to find the normal to the plane. Analyze the coordinates of the points relative to the center into components along the normal and perpendicular. The perpendicular components are a 2D problem, for which you've already found a solution.
Upvotes: 1