Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arranging coordinates into clockwise order

I have 9 screen coordinates, each representing one of 9 positions. From the top right, I want that position to start as the 1st position, and the following clockwise coordinates to represent the 2nd, 3rd, 4th and so on, up until the 9th, which would be the top left coordinate.

Would anybody here be able to come up with some sort of mathematical means of determining which of the 9 coordinates is in which position? They're all relative to each other, and will always be THAT relative to each other.

Example coordinates could be:

(x,y)
X   Y
663 382
543 454
303 454
183 382
418 459
543 209
303 209
653 259
183 259

Plotting into an image something like: Representation of coordinates

Would anybody have any ideas? I simply want some form of programmatic way of listing these coordinates in clockwise order...

like image 870
Tiago Avatar asked Feb 20 '23 22:02

Tiago


1 Answers

Find the center of the "circle," i.e., the average X and average Y

Shift the X and Y values so all are relative to the new center.

Convert to polar coordinates and sort by angle.

like image 52
Doug Currie Avatar answered Mar 05 '23 22:03

Doug Currie