FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf: compute Twist3.Ad() directly instead of via a throwaway SE3 by petercorke · Pull Request #211 · rai-opensource/spatialmath-python · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 4 additions & 3 deletions spatialmath/twist.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,13 @@ def Ad(self):
>>> S = Twist3.Rx(0.3)
>>> S.Ad()

.. note:: This method computes the equivalent SE(3) matrix, then the adjoint
of that.
.. note:: Equivalent to, but faster than, ``self.SE3().Ad()`` -- computes
the adjoint directly from the twist's exponential without
constructing an intermediate ``SE3`` instance.

:seealso: :func:`Twist3.ad`, :func:`Twist3.SE3`, :func:`Twist3.exp`
"""
return self.SE3().Ad()
return smb.tr2adjoint(smb.trexp(self.S, check=False))

def skewa(self):
"""
Expand Down
26 changes: 26 additions & 0 deletions tests/test_twist.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ def test_exp(self):
tw = Twist3.UnitRevolute([0, 0, 1], [0, 0, 0])
array_compare(tw.exp(pi / 2), SE3.Rz(pi / 2))

def test_Ad(self):
# pure rotation: Ad is block-diagonal [[R,0],[0,R]], no translation
# coupling -- hand-verified ground truth, not derived from Ad() itself.
R = SE3.Rx(0.4).R
S = Twist3(SE3.Rx(0.4))
expected = np.zeros((6, 6))
expected[:3, :3] = R
expected[3:, 3:] = R
nt.assert_almost_equal(S.Ad(), expected)

# pure translation: Ad couples translation into the top-right block
# via skew(t), identity rotation blocks -- also hand-verified.
t = np.r_[1, 2, 3]
S = Twist3(SE3(t))
expected = np.eye(6)
expected[:3, 3:] = skew(t)
nt.assert_almost_equal(S.Ad(), expected)

# general case: cross-check against SE3.Ad(), computed from the same
# twist's own exponential, for several random transforms.
for _ in range(20):
T = SE3.Rand()
S = Twist3(T)
nt.assert_almost_equal(S.Ad(), S.SE3().Ad())
nt.assert_almost_equal(S.Ad(), T.Ad())

def test_arith(self):
# check overloaded *

Expand Down
Loading

Back | FazBrowse Home | New Git URL