Skip to content

Commit d6134bf

Browse files
authored
[Issue-126] fix several issues with animate (#131)
Fix several issues related to #126 - expose "ax" and "dims" arguments to animate(...), to be consistent with other API's; - update animate implementation to be consistent with trajectory frame's data type, in particular, SE3Array / SO3Array types instead of SE3 / SO3, in line with animate.run(...)'s implementation.
1 parent 53c0ee1 commit d6134bf

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

spatialmath/base/animate.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def __init__(
104104
# ax.set_zlim(dims[4:6])
105105
# # ax.set_aspect('equal')
106106
ax = smb.plotvol3(ax=ax, dim=dim)
107+
if dim is not None:
108+
dim = list(np.ndarray.flatten(np.array(dim)))
109+
if len(dim) == 2:
110+
dim = dim * 3
111+
elif len(dim) != 6:
112+
raise ValueError(f"dim must have 2 or 6 elements, got {dim}. See docstring for details.")
113+
ax.set_xlim(dim[0:2])
114+
ax.set_ylim(dim[2:4])
115+
ax.set_zlim(dim[4:])
107116

108117
self.ax = ax
109118

@@ -208,10 +217,12 @@ def update(frame, animation):
208217
if isinstance(frame, float):
209218
# passed a single transform, interpolate it
210219
T = smb.trinterp(start=self.start, end=self.end, s=frame)
211-
else:
212-
# assume it is an SO(3) or SE(3)
220+
elif isinstance(frame, NDArray):
221+
# type is SO3Array or SE3Array when Animate.trajectory is not None
213222
T = frame
214-
# ensure result is SE(3)
223+
else:
224+
# [unlikely] other types are converted to np array
225+
T = np.array(frame)
215226

216227
if T.shape == (3, 3):
217228
T = smb.r2t(T)
@@ -309,7 +320,7 @@ def __init__(self, anim: Animate, h, xs, ys, zs):
309320
self.anim = anim
310321

311322
def draw(self, T):
312-
p = T.A @ self.p
323+
p = T @ self.p
313324
self.h.set_data(p[0, :], p[1, :])
314325
self.h.set_3d_properties(p[2, :])
315326

@@ -367,7 +378,7 @@ def __init__(self, anim, h):
367378

368379
def draw(self, T):
369380
# import ipdb; ipdb.set_trace()
370-
p = T.A @ self.p
381+
p = T @ self.p
371382

372383
# reshape it
373384
p = p[0:3, :].T.reshape(3, 2, 3)
@@ -421,7 +432,7 @@ def __init__(self, anim, h, x, y, z):
421432
self.anim = anim
422433

423434
def draw(self, T):
424-
p = T.A @ self.p
435+
p = T @ self.p
425436
# x2, y2, _ = proj3d.proj_transform(
426437
# p[0], p[1], p[2], self.anim.ax.get_proj())
427438
# self.h.set_position((x2, y2))
@@ -546,8 +557,6 @@ def __init__(
546557
axes.set_xlim(dims[0:2])
547558
axes.set_ylim(dims[2:4])
548559
# ax.set_aspect('equal')
549-
else:
550-
axes.autoscale(enable=True, axis="both")
551560

552561
self.ax = axes
553562

spatialmath/base/transforms2d.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,12 +1510,9 @@ def tranimate2(T: Union[SO2Array, SE2Array], **kwargs):
15101510
tranimate2(transl(1,2)@trot2(1), frame='A', arrow=False, dims=[0, 5])
15111511
tranimate2(transl(1,2)@trot2(1), frame='A', arrow=False, dims=[0, 5], movie='spin.mp4')
15121512
"""
1513-
anim = smb.animate.Animate2(**kwargs)
1514-
try:
1515-
del kwargs["dims"]
1516-
except KeyError:
1517-
pass
1518-
1513+
dims = kwargs.pop("dims", None)
1514+
ax = kwargs.pop("ax", None)
1515+
anim = smb.animate.Animate2(dims=dims, axes=ax, **kwargs)
15191516
anim.trplot2(T, **kwargs)
15201517
return anim.run(**kwargs)
15211518

spatialmath/base/transforms3d.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,12 +3409,9 @@ def tranimate(T: Union[SO3Array, SE3Array], **kwargs) -> str:
34093409
34103410
:seealso: `trplot`, `plotvol3`
34113411
"""
3412-
anim = Animate(**kwargs)
3413-
try:
3414-
del kwargs["dims"]
3415-
except KeyError:
3416-
pass
3417-
3412+
dim = kwargs.pop("dims", None)
3413+
ax = kwargs.pop("ax", None)
3414+
anim = Animate(dim=dim, ax=ax, **kwargs)
34183415
anim.trplot(T, **kwargs)
34193416
return anim.run(**kwargs)
34203417

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy