   ordering a set of points
  Hi,I have a bitmap that has a bunch of points that form an enclosure. These are all the edge points of this shape. I need to order the points though so I can pass it as a bunch of line segments to a 3d engine to display as a polygon.Right now since my points are all out of order, the 3d engine tries connecting the edge points in whatever random order they're in and it looks horrific. The shape might look like this: (x's are screen pixels, the * is a special case I am having a problem with):xxxxxxxxxxx*xx   x    x   x   xxx   xxxx  x   xxxxxxxxxxxSo this is problematic because each point could have more than two neighbors to choose from to keep making a circuit, like in the upper left of the shape where I marked the edge pixel with a *. Any ideas of a consistent method I could use to get all the points in order?Thanks,Mark   
  Easy, surround the group with a circular ordered group of points, and then shrink the circle down until it matches the shape, or coincides with itself.   ;  Start from a northeasternmost vertex (no neighbours to east and north, there might be a bunch of those, doesn't matter which you choose), it has neighbours to the west and to the south; proceed to the west, and from that point on, always choose the first neighbour counter-clockwise from the one you just left. Illustration:  ?.xx. .xx. .xx. .xx. .xx. .xx. .x?. .x3. .x3? .x3. .?3. .43. .43.xxx. xxx. xx?. xx2. xx2. xx2? xx2. xx2. xx2. xx2. xx2. xx2. x52...x* ..1* ..1* ..1* ..1* ..1* ..1* ..1* ..1* ..1* ..1* ..1* ..1*...x ...x ...x ...x ...x ...x ...x ...x ...x ...x ...x ...x ...xetc. (? is your testing of whether a point is a vertex or not)As long as you have a polygon that has no holes, this will work. Example of a polygon that will fail this:........xxxxxx..xxxxxx..xx..xx..xx..xx..xxxxxx..xxxxxx.........This represents many polygons (depending on where you cut the "doughnut"), so those cases are ambiguous anyway.   ;  Thanks guys, looks like that will work perfectly,Mark   