Last active
March 1, 2021 20:02
-
-
Save CarstenSchelp/51974be76b0424c7cbc43fead29c4d1b to your computer and use it in GitHub Desktop.
convert arctan2 result from -1*pi .. +1*pi to 0 .. 2*pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The arctan2 funtion returns an angle between -PI and +PI (radians) | |
# If you need a range from zero to 2PI, this is how the | |
# arctan2 result can be converted. | |
# Zero still means "aligned with the 'x' axis" | |
# And the angle is still to be interpreted counter-clockwise. | |
import numpy as np | |
def arctan2_2pi(y, x): | |
return -1 * ( | |
np.arctan2( | |
y, (-1) * x | |
) - np.pi | |
) | |
assert arctan2_2pi(0, 1) == 0 | |
assert arctan2_2pi(1, 1) == np.pi/4 | |
assert arctan2_2pi(1, 0) == np.pi/2 | |
assert arctan2_2pi(1, -1) == 3*np.pi/4 | |
assert arctan2_2pi(0, -1) == np.pi | |
assert arctan2_2pi(-1, -1) == 5 * np.pi/4 | |
assert arctan2_2pi(-1, 0) == 3 * np.pi/2 | |
assert arctan2_2pi(-1, 1) == 7 * np.pi/4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment