atan2
Four-quadrant inverse tangent.
Category: Mathematics > Elementary Math
Syntax
P = atan2(Y, X)
Returns the angle of the point (X, Y) measured from the positive x-axis, in radians.
Description
Unlike atan(Y ./ X), atan2 uses the signs of both arguments to place the angle in the correct quadrant. The point (-1, 1) gives 3*pi/4, whereas atan(1/-1) gives -pi/4. It also handles X = 0 without dividing, and atan2(0, 0) is 0.
Note the argument order: Y comes first.
Input arguments
Y- Real array of y-coordinates.
X- Real array of x-coordinates. It must have the same size as
Y, or one of them must be a scalar.
Output arguments
P- Angle in
[-pi, pi].
Example
Angles in each quadrant
atan2([1 1 -1 -1], [1 -1 -1 1])
Output
ans = 1×4
0.7854 2.3562 -2.3562 -0.7854