Added wind vector animation
This commit is contained in:
@@ -40,7 +40,7 @@ def _decimate_index(time, sample_time):
|
||||
sample_index = np.round(np.interp(sample_time, time, index)).astype(int)
|
||||
return sample_index
|
||||
|
||||
def animate(time, position, rotation, world, filename=None, blit=False, show_axes=True, close_on_finish=False):
|
||||
def animate(time, position, rotation, wind, animate_wind, world, filename=None, blit=False, show_axes=True, close_on_finish=False):
|
||||
"""
|
||||
Animate a completed simulation result based on the time, position, and
|
||||
rotation history. The animation may be viewed live or saved to a .mp4 video
|
||||
@@ -54,6 +54,8 @@ def animate(time, position, rotation, world, filename=None, blit=False, show_axe
|
||||
time, (N,) with uniform intervals
|
||||
position, (N,3)
|
||||
rotation, (N,3,3)
|
||||
wind, (N,3) world wind velocity
|
||||
animate_wind, if True animate wind vector
|
||||
world, a World object
|
||||
filename, for saved video, or live view if None
|
||||
blit, if True use blit for faster animation, default is False
|
||||
@@ -65,6 +67,13 @@ def animate(time, position, rotation, world, filename=None, blit=False, show_axe
|
||||
rtf = 1.0 # real time factor > 1.0 is faster than real time playback
|
||||
render_fps = 30
|
||||
|
||||
# Normalize the wind by the max of the wind magnitude on each axis, so that the maximum length of the arrow is decided by the scale factor
|
||||
wind_mag = np.linalg.norm(wind, axis=1) # Get the wind magnitude time series
|
||||
max_wind = np.max(wind_mag) # Find the maximum wind magnitude in the time series
|
||||
if max_wind != 0:
|
||||
wind_arrow_scale_factor = 1 # Scale factor for the wind arrow
|
||||
wind = wind_arrow_scale_factor*wind / max_wind # Apply scaling on wind.
|
||||
|
||||
# Decimate data to render interval; always include t=0.
|
||||
if time[-1] != 0:
|
||||
sample_time = np.arange(0, time[-1], 1/render_fps * rtf)
|
||||
@@ -74,6 +83,7 @@ def animate(time, position, rotation, world, filename=None, blit=False, show_axe
|
||||
time = time[index]
|
||||
position = position[index,:]
|
||||
rotation = rotation[index,:,:]
|
||||
wind = wind[index,:]
|
||||
|
||||
# Set up axes.
|
||||
if filename is not None:
|
||||
@@ -91,7 +101,7 @@ def animate(time, position, rotation, world, filename=None, blit=False, show_axe
|
||||
ax.set_ylim(-1,1)
|
||||
ax.set_zlim(-1,1)
|
||||
|
||||
quad = Quadrotor(ax)
|
||||
quad = Quadrotor(ax, wind=animate_wind)
|
||||
|
||||
world_artists = world.draw(ax)
|
||||
|
||||
@@ -103,7 +113,7 @@ def animate(time, position, rotation, world, filename=None, blit=False, show_axe
|
||||
|
||||
def update(frame):
|
||||
title_artist.set_text('t = {:.2f}'.format(time[frame]))
|
||||
quad.transform(position=position[frame,:], rotation=rotation[frame,:,:])
|
||||
quad.transform(position=position[frame,:], rotation=rotation[frame,:,:], wind=wind[frame,:])
|
||||
[a.do_3d_projection(fig.canvas.get_renderer()) for a in quad.artists]
|
||||
return world_artists + list(quad.artists) + [title_artist]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user