3

I have a set of points that are on the boundary of a concave polygon. I would like to find one non crossing polygon that have these points as vertices. In other words, I would like to order in a ccw (or cw) manner vertices of a concave polygon.

I had a look at methods to evaluate whether a polygon is ordered in ccw or cw manner (compute and sum cross products). It is not exactly my problem: I have the vertices in random sequence, and I want to order them so as to have them cw or ccw on the crust of the polygon.

I thought of taking the initial sequence of vertices, and successively identify crossings. If initial points sequence is [x1,y1 ; x2, y2 ; x3, y3 ; ...] and 2nd and 3rd points are crossing, we continue with sequence [x1,y1 ; x2, y3 ; x3, y2 ; ...]

What algorithm can you think of? what are notions behind? Do you have hints at some references?

alpha shape

Regds

kiriloff
  • 25,609
  • 37
  • 148
  • 229
  • It's not clear what you mean by crossing points. Do you mean crossing lines ? In your example you seem to be changing the points - from (x2,y2) and (x3, y3) to (x2, y3) and (x3, y2) ? – krjampani Sep 16 '12 at 13:18

2 Answers2

5

If I understood the problem correctly, you want to order the input set of points so that they appear in clockwise order of some possibly concave polygon. This can be solved as follows.

enter image description here

Let p1 and p2 be the left-most and right-most points. Find a lower convex hull S of the points. S contains p1, p2 and all the convex hull points that are below the line p1p2. Now sort the remaining points (those not in S) by their x-coordinate. This sorted order together with the order of S (generated by the lower convex hull algorithm) will give you a desired clockwise order of all the vertices.

krjampani
  • 2,902
  • 20
  • 23
  • Not exactly: I want to order vertices of a polygon, which is concave. I cannot do with the convex hull method then, or am I missing something? thanks for your input. – kiriloff Sep 16 '12 at 13:51
  • You are only computing the lower half-of the convex hull. The final order of the points can still be the order of a concave polygon. I have added a picture to make this more clear. – krjampani Sep 16 '12 at 14:12
  • I have a crescent shape. order of lower hull points wont help me much finding order of points, which are all above most left and most right points !? I think I dont understand your last sentence: can you clarify or reword: 'This sorted order together with the order of S (generated by the lower convex hull algorithm) will give you a desired clockwise order of all the vertices.' – kiriloff Sep 16 '12 at 14:17
  • We are dividing the vertices into two sets. One set (S) contains the points of the lower convex hull. These are connected by the black edges in the figure. The remaining vertices are simply sorted from left to right. These are connected by the blue-edges. It is easy to see that no two blue edges cross each other since the points are sorted. Also, it is easy to see that a blue edge doesn't cross a black edge. Thus the black and blue edges together combined represent the circular order of all the points of a concave polygon. – krjampani Sep 16 '12 at 14:38
  • thanks!! lets have a look now at my set of points (points in red in the figure). I want to join the red points to obtain the shape contour (dont care about red lines). With our approach: I find the lower part of convex-hull. Above, I have a lot of points, which i cannot order along x-coordinate to have satisfactory result. or did I misunderstood? could you explain how your method solves this case? thanks again!! – kiriloff Sep 23 '12 at 10:01
  • For points that have the same x-coordinate, you can order them by increasing y-coordinate. That is enough to construct a concave polygon. – krjampani Sep 23 '12 at 12:14
  • yes you are right. its not the polygon I want but it is one polygon ! – kiriloff Sep 23 '12 at 18:20
  • do you thing it would be possible to compute minimum spanning tree for these red points? i am trying right now, what is your opinion? thanks for your ideas!! – kiriloff Sep 24 '12 at 13:41
  • We can construct a minimum spanning tree, but it's not clear how to convert it into a polygon. – krjampani Sep 24 '12 at 15:13
0

There is information at the time the polygon is constructed that must be used unless the polygon is better defined than a set of points that could be a concave polygon I think.

For example, if the vertices are taken from a shape or image then the filled pixels in the shape can be helpful. For one project I need to order points on the perimeter of blobs, so I get the border pixels of the blob (can be done in many ways), then I use a DFS style traversal through those to put them in sequence. I then wrote algorithms to merge edges and make decisions at junctions.