8000 add angle wrapping functions · krishanrana/spatialmath-python@d2e167a · GitHub
[go: up one dir, main page]

Skip to content

Commit d2e167a

Browse files
committed
add angle wrapping functions
1 parent 90b6166 commit d2e167a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spatialmath/base/vectors.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,27 @@ def unittwist2_norm(S):
499499

500500
return (S / th, th)
501501

502+
def wrap_0_2pi(theta):
503+
r"""
504+
Wrap angle to range [0, 2pi)
505+
506+
:param theta: input angle
507+
:type theta: scalar or ndarray
508+
:return: angle wrapped into range :math:`[0, 2\pi)`
509+
"""
510+
return theta - 2.0 * math.pi * np.floor(theta / 2.0 / np.pi)
511+
512+
513+
def wrap_mpi_pi(angle):
514+
r"""
515+
Wrap angle to range [-pi, pi)
516+
517+
:param theta: input angle
518+
:type theta: scalar or ndarray
519+
:return: angle wrapped into range :math:`[-\pi, \pi)`
520+
"""
521+
return np.mod(angle + math.pi, 2 * math.pi) - np.pi
522+
502523

503524
def angdiff(a, b=None):
504525
"""

0 commit comments

Comments
 (0)
0