Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions spatialmath/base/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ def trplot(
else:
self.start = start

# draw axes at the origin
smb.trplot(self.start, ax=self, **kwargs)
# Store frame geometry at the origin so each absolute pose is applied once.
smb.trplot(np.identity(4), ax=self, **kwargs)
self._draw(self.start)

def set_proj_type(self, proj_type: str):
self.ax.set_proj_type(proj_type)
Expand Down
29 changes: 29 additions & 0 deletions tests/base/test_transforms3d_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,38 @@
from spatialmath.base.transformsNd import isR, t2r, r2t, rt2tr

import matplotlib.pyplot as plt
from spatialmath.base.animate import Animate


class Test3D(unittest.TestCase):
def test_animate_nonidentity_start(self):
start = transl(-1, 0, 2) @ trotz(0.4)
end = transl(1, 2, 1) @ trotx(0.3)
for style in ("line", "arrow", "rviz"):
fig = plt.figure()
try:
anim = Animate(dim=[-4, 4])
anim.trplot(end, start=start, style=style, frame="moving")
for pose in (start, end):
anim._draw(pose)
for obj in anim.displaylist:
expected = pose @ obj.p if hasattr(obj, "p") else None
if obj.type == "line":
nt.assert_allclose(
np.asarray(obj.h.get_data_3d()),
expected[:3],
atol=1e-14,
)
nt.assert_allclose(obj.p[:3, 0], np.zeros(3), atol=1e-14)
elif obj.type == "arrow":
nt.assert_allclose(
np.asarray(obj.h._segments3d),
expected[:3].T.reshape(3, 2, 3),
atol=1e-14,
)
finally:
plt.close(fig)

@pytest.mark.skipif(
os.environ.get("CI") == "true"
or (sys.platform.startswith("darwin") and sys.version_info < (3, 11)),
Expand Down
Loading