In C-MATH.H or C + +, there are two Cmath function atan (double x) with atan2 (double y,double x) and the value they return is the radian to be converted to an angle and then processed by itself.
The former accepts a tangent (the slope of the line) to get the angle, but because the tangent of the regularity can have two angles, but it only returns one, because the Atan range is from -90~90 that it only handles 14 quadrants, so it is generally not used.
The second atan2 (double y,double x) where y represents the y-coordinate of the known point x, the return value is the angle between this point and the far point line and the x-axis positive direction, so that it can handle four quadrants of any case, its range corresponding to that is -180~180
For example:
Example 1: The angle of a straight line with a slope of 1
Cout<<atan (1.0) *180/pi;//45°
Cout<<atan2 (1.0,1.0) *180/pi;//45° first quadrant
Cout<<atan2 ( -1.0,-1.0) *180/pi;//-135° third quadrant
The last two slopes are 1 but the atan can only find a 45°
Example 2: The angle of a line with a slope of-1
Cout<<atan ( -1.0) *180/pi;//-45°
Cout<<atan2 ( -1.0,1.0) *180/pi;//-45°y negative in fourth quadrant
Cout<<atan2 (1.0,-1.0) *180/pi;//135°x negative in the second quadrant
The usual is not to seek the origin of the line of the angle is often to find the angle of a line segment this is more like a duck to atan2.
For example, a (1.0,1.0) B (3.0,3.0) This segment AB and the x-axis positive direction of the angle
denoted by atan2 as atan2 (y2-y1,x2-x1) or atan2 (3.0-1.0,3.0-1.0)
The principle is equivalent to translating point A to the Origin point B to B ' (x2-x1,y2-y1) point and then back to the previous
Example three:
A (0.0,5.0) B (5.0,10.0)
The angle of the line AB is
Cout<<atan2 (5.0,5.0) *180/pi;//45°
^_^
Atan and atan2 in the C language