Skip to content

Commit 12cf3db

Browse files
committed
animate.trplot;anmiate.trplot2 allows iterable trajectory argument
1 parent 4fea621 commit 12cf3db

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎spatialmath/base/animate.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def __init__(self, axes=None, dims=None, labels=('X', 'Y'), **kwargs):
412412
Will setup to plot into an existing or a new Axes3D instance.
413413
414414
"""
415+
self.trajectory = None
415416
self.displaylist = []
416417

417418
if axes is None:
@@ -453,6 +454,12 @@ def trplot2(self, end, start=None, **kwargs):
453454
:seealso: :func:`run`
454455
455456
"""
457+
if not isinstance(end, (np.ndarray, np.generic) ) and isinstance(end, Iterable):
458+
if len(end) == 1:
459+
end = end[0]
460+
elif len(end) >= 2:
461+
self.trajectory = end
462+
456463
# stash the final value
457464
if base.isrot2(end):
458465
self.end = base.r2t(end)
@@ -496,7 +503,11 @@ def run(self, movie=None, axes=None, repeat=False, interval=50, nframes=100, **k
496503
"""
497504

498505
def update(frame, a):
499-
T = base.trinterp2(start=self.start, end=self.end, s=frame / nframes)
506+
# if contains trajectory:
507+
if self.trajectory is not None:
508+
T = self.trajectory[frame]
509+
else:
510+
T = base.trinterp2(start=self.start, end=self.end, s=frame / nframes)
500511
a._draw(T)
501512
if frame == nframes - 1:
502513
a.done = True
@@ -507,6 +518,8 @@ def update(frame, a):
507518
repeat = False
508519

509520
self.done = False
521+
if self.trajectory is not None:
522+
nframes = len(self.trajectory)
510523
ani = animation.FuncAnimation(fig=plt.gcf(), func=update, frames=range(0, nframes), fargs=(self,), blit=False, interval=interval, repeat=repeat)
511524

512525
if movie is None:

0 commit comments

Comments
 (0)