Skip to content

Instantly share code, notes, and snippets.

@winstxnhdw
Last active July 31, 2023 15:36
Show Gist options
  • Save winstxnhdw/593105601d9199d75852b1584a610c02 to your computer and use it in GitHub Desktop.
Save winstxnhdw/593105601d9199d75852b1584a610c02 to your computer and use it in GitHub Desktop.
Normalises angle between -pi to pi.
from math import atan2, sin, cos
def normalise_angle(angle: float):
"""
Summary
-------
normalise an angle to the range [-pi, pi]
Parameters
----------
angle (float): angle [rad]
Returns
-------
normalised_angle (float): angle [rad]
"""
return atan2(sin(angle), cos(angle))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment