i wrote a program to arrange points on a graph in clockwise manner from 12 o\'clock such that, a vector containing these points is sorted in that order. I am using atan2 to ge
You don't need the adjustment. atan2
will give you the angle from positive direction of x axis, counterclockwise in range of -PI to PI.
Firstly, to make the starting point positive direction of y axis, let me give parameter to atan2
as if negative direction of y axis is positive direction of x axis and positive direction of x axis is positive direction is y axis.
Then, this will make the angle counterclockwise, so negate the angle in order to reverse the order.
double get_clockwise_angle(const Point& p)
{
double angle = 0.0;
int quadrant = get_quadrant(p);
/*making sure the quadrants are correct*/
cout << "Point: " << p << " is on the " << quadrant << " quadrant" << endl;
/*calculate angle and return it*/
angle = -atan2(p.x,-p.y);
return angle;
}