scipp.atan2#

scipp.atan2(*, y, x, out=None)#

Element-wise inverse tangent of y/x determining the correct quadrant.

Unlike atan(y/x), this function uses the signs of both arguments to determine the correct quadrant of the result.

Parameters:
Returns:

Variable – The signed inverse tangent values of y/x in the range [-π, π].

See also

https://en.cppreference.com/w/c/numeric/math/atan2:

Documentation of all edge cases. Note that domain errors are not propagated to Python.

numpy.arctan2:

The equivalent in NumPy with additional explanations.

Examples

Compute the angle in radians between the positive x-axis and the point (x, y):

>>> import scipp as sc
>>> y = sc.array(dims=['point'], values=[0.0, 1.0, 1.0], unit='m')
>>> x = sc.array(dims=['point'], values=[1.0, 0.0, 1.0], unit='m')
>>> sc.atan2(y=y, x=x)
<scipp.Variable> (point: 3)    float64            [rad]  [0, 1.5708, 0.785398]

The x and y arguments must have the same unit. The output is in radians:

>>> y = sc.array(dims=['point'], values=[1.0, -1.0], unit='m')
>>> x = sc.array(dims=['point'], values=[-1.0, -1.0], unit='m')
>>> sc.atan2(y=y, x=x).to(unit='deg')
<scipp.Variable> (point: 2)    float64            [deg]  [135, -135]