How to plot Cycloid with python
Do you already see the animation of “Cycloid”? Do you want to plot it yourself with python? This tutorial will show how to plot Cycloid with python.
Python libraries
pip install matplotlib
pip install numpy
Plotted figure
Utils functions
Two utils function to plot circle and bar:
def circle(x0,y0,color=’r’,r=1):
t=np.arange(0,2*np.pi,1./100)
x=np.cos(t)*r+x0
y=np.sin(t)*r+y0
plt.plot(x,y,color=color)
def bar(x0,y0,theta,color=’m’,r=1):
rr=np.arange(0,r,1./100)
x=np.cos(theta)*rr+x0
y=np.sin(theta)*rr+y0
plt.plot(x,y,color=color)
main plot code
# plot cycloid
theta=np.arange(0,2*np.pi,1./100)
x=theta-np.sin(theta)
y=1-np.cos(theta)
plt.axis(‘equal’)
plt.plot(x,y,’y’)
# plot origin circle (x0=0,y0=1)
circle(0,1,’r’)
bar(0,1,-np.pi/2,’r’)
# plot circle 1
theta=np.pi*0.4
circle(theta,1,’g’)
bar(theta,1,-theta-np.pi/2,’g’)
bar(theta,1,-np.pi/2,’c’)
# plot circle 2
theta=np.pi*1.4
circle(theta,1,’b’)
bar(theta,1,-theta-np.pi/2,’b’)
bar(theta,1,-np.pi/2,’c’)
Have fun ^_^