Skip to content

Commit c3f08ad

Browse files
committed
add new function for wrapping latitude angles
1 parent 25f3077 commit c3f08ad

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_pi(theta):
503+
r"""
504+
Wrap angle to range [0, pi]
505+
506+
:param theta: input angle
507+
:type theta: scalar or ndarray
508+
:return: angle wrapped into range :math:`[0, \pi)`
509+
510+
This is used to fold angles of colatitude. If zero is the angle of the
511+
north pole, colatitude increases to :math:`\pi` at the south pole then
512+
decreases to :math:`0` as we head back to the north pole.
513+
"""
514+
n = (theta / np.pi)
515+
if isinstance(n, np.ndarray):
516+
n = astype(int)
517+
else:
518+
n = int(n)
519+
520+
return np.where(n & 1 == 0, theta - n * np.pi, (n+1) * np.pi - theta)
521+
522+
502523
def wrap_0_2pi(theta):
503524
r"""
504525
Wrap angle to range [0, 2pi)

0 commit comments

Comments
 (0)