Skip to content

Commit

Permalink
Add assert_mrp_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderFabisch committed Oct 22, 2024
1 parent 5f69606 commit 47dd896
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Modified Rodrigues Parameters
~concatenate_mrp
~mrp_from_axis_angle
~mrp_from_quaternion
~assert_mrp_equal

Jacobians
---------
Expand Down
3 changes: 2 additions & 1 deletion pytransform3d/rotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
axis_angle_slerp, rotor_slerp)
from ._testing import (
assert_euler_equal, assert_quaternion_equal, assert_axis_angle_equal,
assert_compact_axis_angle_equal, assert_rotation_matrix)
assert_compact_axis_angle_equal, assert_rotation_matrix, assert_mrp_equal)
from ._plot import plot_basis, plot_axis_angle, plot_bivector
from ._rotors import (
wedge, geometric_product, rotor_apply, rotor_reverse, concatenate_rotors,
Expand Down Expand Up @@ -245,6 +245,7 @@
"assert_axis_angle_equal",
"assert_compact_axis_angle_equal",
"assert_rotation_matrix",
"assert_mrp_equal",
"plot_basis",
"plot_axis_angle",
"wedge",
Expand Down
30 changes: 30 additions & 0 deletions pytransform3d/rotations/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from numpy.testing import assert_array_almost_equal
from ._utils import norm_axis_angle, norm_compact_axis_angle
from ._conversions import norm_euler
from ._mrp import mrp_double


def assert_euler_equal(e1, e2, i, j, k, *args, **kwargs):
Expand Down Expand Up @@ -159,3 +160,32 @@ def assert_rotation_matrix(R, *args, **kwargs):
"""
assert_array_almost_equal(np.dot(R, R.T), np.eye(3), *args, **kwargs)
assert_array_almost_equal(np.linalg.det(R), 1.0, *args, **kwargs)


def assert_mrp_equal(mrp1, mrp2, *args, **kwargs):
"""Raise an assertion if two MRPs are not approximately equal.
There are two MRPs that represent the same orientation (double cover). See
numpy.testing.assert_array_almost_equal for a more detailed documentation
of the other parameters.
Parameters
----------
mrp1 : array-like, shape (3,)
Modified Rodrigues parameters.
mrp1 : array-like, shape (3,)
Modified Rodrigues parameters.
args : tuple
Positional arguments that will be passed to
`assert_array_almost_equal`
kwargs : dict
Positional arguments that will be passed to
`assert_array_almost_equal`
"""
try:
assert_array_almost_equal(mrp1, mrp2, *args, **kwargs)
except AssertionError:
assert_array_almost_equal(mrp1, mrp_double(mrp2), *args, **kwargs)
3 changes: 3 additions & 0 deletions pytransform3d/rotations/_testing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ def assert_quaternion_equal(q1: npt.ArrayLike, q2: npt.ArrayLike, *args, **kwarg


def assert_rotation_matrix(R: npt.ArrayLike, *args, **kwargs): ...


def assert_mrp_equal(mrp1: npt.ArrayLike, mrp2: npt.ArrayLike, *args, **kwargs): ...
1 change: 1 addition & 0 deletions pytransform3d/test/test_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,7 @@ def test_mrp_double():
mrp_double = pr.mrp_double(mrp)
q = pr.quaternion_from_mrp(mrp)
q_double = pr.quaternion_from_mrp(mrp_double)
pr.assert_mrp_equal(mrp, mrp_double)
assert not np.allclose(mrp, mrp_double)
pr.assert_quaternion_equal(q, q_double)
assert not np.allclose(q, q_double)
Expand Down

0 comments on commit 47dd896

Please sign in to comment.