Référentiels en rotation autour d'un axe fixe
¶

In [1]:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [10, 10]
import matplotlib.animation as animation
from IPython.display import HTML
In [3]:
P0 = [-10,-10]
V = [1,1]
N = 20
t = np.arange(N)
x = P0[0]+V[0]*t
y = P0[1]+V[1]*t
xp = np.zeros(N)
yp = np.zeros(N)
w = np.pi/30
L = 20
xc = np.array([-L,L,L,-L,-L])
yc = np.array([-L,-L,L,L,-L])

fig,ax = plt.subplots()
ax.axis([-30,30,-30,30])
ax.grid()
ax.set_aspect('equal')
pointsR, = ax.plot([],[],'ko')
pointsRp, = ax.plot([],[],'ro')
cadreRp, = ax.plot([],[],'r-')

def animate(i):
    global x,y,w,pointsR,pointsRp
    pointsR.set_xdata(x[0:i])
    pointsR.set_ydata(y[0:i])
    theta = w*i
    cos = np.cos(theta)
    sin = np.sin(theta)
    cadreRp.set_xdata(xc*cos-yc*sin)
    cadreRp.set_ydata(xc*sin+yc*cos)
    for k in range(i):
        theta = w*(i-1-k)
        cos = np.cos(theta)
        sin = np.sin(theta)
        xp[k] = x[k]*cos-y[k]*sin
        yp[k] = x[k]*sin+y[k]*cos
        pointsRp.set_xdata(xp[0:i])
        pointsRp.set_ydata(yp[0:i])

anim = animation.FuncAnimation(fig,animate,N,interval=1000,repeat=True)
#anim.save('rotationReferentiel.mp4')
HTML(anim.to_html5_video())
Out[3]:
Your browser does not support the video tag.
In [ ]: