lundi 14 juin 2021

sort coordinates in vector by anticlockwise order

I have vector holding some coordinates

exmp :

struct Point {

    long long int x, y;
    bool operator<(Point p)
    {
        return x < p.x || (x == p.x && y < p.y);
    }
};

vector<Point> v { { -3, -4 },{ 2, -3 },{ 4, 3 },{ -4, 2 },{ 0, 5 } };

and what I'm willing to do is to sort these coordinates by anticlockwise order starting from the first point

(in this case starting from {-3,-4} )

example of output and input :

input : { { -3, -4 },{ 2, -3 },{ 4, 3 },{ -4, 2 },{ 0, 5 } }

output : { { -3, -4 },{ 2, -3 },{ 4, 3 },{ 0, 5 },{ -4,-2 } }

please see image for better explanation

(p.s. coordinates on the picture don't match with vector<Points> v coordinates)

if you have any suggestions or tips, please don't hesitate, I will be thankful

(yes i know, I'm bad in maths :V )

Aucun commentaire:

Enregistrer un commentaire