Skip to content

Commit

Permalink
Fix double cover function of MRP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderFabisch committed Oct 29, 2024
1 parent 624ff64 commit be61146
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pytransform3d/rotations/_mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def mrp_double(mrp):
\boldsymbol{\psi}` represent the same rotation and correspond to two
antipodal unit quaternions [1]_.
No rotation is a special case, in which no second representation exists.
Only the zero vector represents no rotation.
Parameters
----------
mrp : array-like, shape (3,)
Expand All @@ -78,7 +81,10 @@ def mrp_double(mrp):
http://malcolmdshuster.com/Pub_1993h_J_Repsurv_scan.pdf
"""
mrp = check_mrp(mrp)
return mrp / -np.dot(mrp, mrp)
norm = np.dot(mrp, mrp)
if norm == 0.0:
return mrp
return mrp / -norm


def concatenate_mrp(mrp1, mrp2):
Expand Down
2 changes: 2 additions & 0 deletions pytransform3d/test/test_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,8 @@ def test_mrp_double():
pr.assert_quaternion_equal(q, q_double)
assert not np.allclose(q, q_double)

assert_array_almost_equal(np.zeros(3), pr.mrp_double(np.zeros(3)))


def test_assert_euler_almost_equal():
pr.assert_euler_equal(
Expand Down

0 comments on commit be61146

Please sign in to comment.