geometry - Sort list of coordinates -


i have following problem: have list of x, y coordinates of polygon's points. need sort them in such way obtain points in clockwise order.

currently have 6 coordinates draw polygon not in order.

does know how accomplish that?

input coordinates :

coordinate: 506.6609866568262, 673.970398950142

coordinate: 505.34898334317376, 682.8179210498581

coordinate: 502.0723751660178, 680.523615304454

coordinate: 534.3026433431738, 682.736131049858

coordinate: 535.6146466568263, 673.8886089501419

coordinate: 538.8912548339822, 676.1829146955461

output coordinates :

coordinate: 506.6609866568262, 673.970398950142

coordinate: 502.0723751660178, 680.523615304454

coordinate: 505.34898334317376, 682.8179210498581

coordinate: 534.3026433431738, 682.736131049858

coordinate: 538.8912548339822, 676.1829146955461

coordinate: 535.6146466568263, 673.8886089501419

thanks in advance,

use polar coordinates:

  1. find internal point polygon reference, (c,d);
  2. use atan2(x-c, y-d) each vertex (x,y) of polygon polar angles internal point; then
  3. sort angles get.

if polygon convex, averaging max , min values of x , likewise y should internal point. otherwise, have more work do.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -