Pendulum waves
Python code :
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
col = ["red","orange","yellow","green","blue","purple","red","orange","yellow","green","blue","purple","red","orange","yellow","green"]
n = 15
for ti in range(3000) :
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot([0,0], [-1,n], [3,3], c='black') # upper bar
ax.plot([0,0], [-1,n], [0,0], c='lightgrey') # upper bar shadow
t = 2*ti/100. /3. #time index
for i in range(n) :
y=i
long = 1.0 +0.05*(20-i) # rope lengths : uniform range
theta = np.cos(t * long * 2*np.pi ) # frequency proportional to length
x= theta # cosinusidal motion in the X-coordinate,
z= 3- np.sqrt( long*long - x*x) # Z from Pythagora (length of the rope does not depend on the angle)
ax.plot([0,x], [y,y], [3,z], c='grey',linewidth=.5) # rope
ax.plot([0,x], [y,y], [0,0], c='lightgrey',linewidth=.5) # rope shadow
ax.scatter(x, y, z,s=60, c=col[i], marker='o') # ball
ax.scatter(x, y, 0,s=60, c='lightgrey', marker='o') # ball shadow
ax.set_xlim3d(-1.5, 1.5)
ax.set_ylim3d(-1,n)
ax.set_zlim3d(0,3)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.view_init(30, 280)
filename = "testimage"+str(ti).zfill(3)+".png"
plt.savefig(filename)
print filename + " saved"
plt.close()
page revision: 1, last edited: 04 Jul 2019 10:34