Skip to content

Instantly share code, notes, and snippets.

@HajimeKawahara
Created October 15, 2024 23:21
Show Gist options
  • Save HajimeKawahara/3cf3da47ce014f4417ed56088ec699a5 to your computer and use it in GitHub Desktop.
Save HajimeKawahara/3cf3da47ce014f4417ed56088ec699a5 to your computer and use it in GitHub Desktop.
import numpy as np
def normalized_angle(theta):
return theta - 2 * np.pi * np.round(theta / (2 * np.pi))
def normalized_angle2(theta):
return np.arctan2(np.sin(theta), np.cos(theta))
if __name__ == "__main__":
theta = np.array([-1.8, -1.2, 0.5, 1.2, 1.8])*np.pi
print(normalized_angle(theta))
print(normalized_angle2(theta))
#shirochan:~/microjax_algo>python temp.py
#[ 0.62831853 2.51327412 1.57079633 -2.51327412 -0.62831853]
#[ 0.62831853 2.51327412 1.57079633 -2.51327412 -0.62831853]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment