Created
February 12, 2019 02:11
-
-
Save Veilkrand/23c3859c45e216b3ac7319321ef5ce1b to your computer and use it in GitHub Desktop.
Unwrapping angles to [-pi,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
## Using Numpy functions result should be [-pi,pi] | |
import numpy as np | |
phases = np.arctan2(np.sin(phases), np.cos(phases)) | |
## equivalen to: | |
phases = np.angle(np.exp(1j*phases)) | |
## Modulo approach | |
phases = (( -phases + np.pi) % (2.0 * np.pi ) - np.pi) * -1.0 | |
## Programmatic approach in C++ | |
double constrainAngle(double x){ | |
x = fmod(x + 180,360); | |
if (x < 0) | |
x += 360; | |
return x - 180; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment