views:

92

answers:

2

I have some points in 3D which are in a single plane. I want to arrange them in clock wise or counter clockwise order.
The points can create a concave or convex polygon in a single plane.
Can any body give any suggestions?

+4  A: 

Find the center of all the points, then calculate all the angles from the center to each point. Then sort by angle.

Ignacio Vazquez-Abrams
But it will not work with points of concave polygon. I had tried it.
Himadri
You never stated that you wanted the original vertex order to be maintained. And if you already have a vertex order then why do you need to arrange the points again?
Ignacio Vazquez-Abrams
@lgnacio I do not have vertex in order. But they all create a polygon if we arrange them in order.
Himadri
They'll create a polygon in *any* order. However, they may not necessarily create the polygon that you hope they will.
Ignacio Vazquez-Abrams
@Ignacio Oh....Yes you are right.It didn't come in my mind. But it also didn't solve my problem. Anyway I should think some other solution for it. Thanks.
Himadri
I believe this to be the solution to the question. Sorting by the atan2f(deltaY, deltaX) (that is, delta from the center of the points) seems to pretty much do the "clockwise ordering" step (if you sort in reverse, hehe).
dash-tom-bang
@dash Can you please explain it more
Himadri
Compute the center of the points. You need to do this because "clockwise" implies that there's a "center" that you're rotating around. For each point, compute the "delta" from this center point. Then each point gets a "score" which comes from atan2f(dY, dX). Sort by this score and you have your ordered list of points.
dash-tom-bang
@dash No, I think I am lacking in explaining my question. But I think my problem can not be solved using points. So, now I am trying to get lines between two consecutive point of my resulting polygon. So, it will be some how easy to arrange lines in sequence.
Himadri
A: 

Ok, I nearly solve the problem. I got line segment instead of having points in 3d. So, Now I have to arrange line segment in sequence. Which becomes somehow easier for me. I am now able to arrange them in sequence.

Himadri