过原点的动直线交定圆 x 2 + y 2 − a y = 0 , a > 0 x^2+y^2-ay=0, a>0 x2+y2−ay=0,a>0于P点,交直线 y = a y=a y=a于Q点,过P和Q分别作X轴和Y轴的平行线交于M点,则M点的轨迹叫做箕舌线 。
设 a = 2 a=2 a=2,则圆的参数方程为
x = cos θ , y = sin θ + 1 x=\cos\theta,y=\sin\theta+1 x=cosθ,y=sinθ+1
设动直线的方程为 y = k x y=kx y=kx,则随着 k k k的变化,可以得到一条箕舌线
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
a = 2
fig = plt.figure(figsize=(15,4))
ax = fig.add_subplot(autoscale_on=False,
xlim=(-5,5),ylim=(-0.1,2.5))
ax.grid()
t = np.arange(0,6.4,0.1)
ax.plot(np.cos(t),np.sin(t)+1,'-',lw=1) #圆方程
ax.plot([-5,5],[a,a],'-',lw=1)
xLine, = ax.plot([],[],linestyle='--',lw=0.5)
yLine, = ax.plot([],[],linestyle='--',lw=0.5)
kLine, = ax.plot([],[],linestyle='--',lw=0.5)
trace, = ax.plot([],[],'-', lw=1)
k_text = ax.text(0.05,0.85,'',transform=ax.transAxes)
textTemplate = 'k = %.1f\n'
xs,ys = [],[]
def animate(theta):
if(theta==0):
xs.clear()
ys.clear()
k = np.tan(theta)
px = 2*k/(k**2+1)
py = k*px
qx = a/k
xLine.set_data([px,qx],[py,py])
yLine.set_data([qx,qx],[2,py])
kLine.set_data([0,qx],[0,a])
xs.append(qx)
ys.append(py)
trace.set_data(xs,ys)
k_text.set_text(textTemplate % k)
return xLine, yLine, kLine, trace, k_text
frames = np.arange(0,np.pi,0.05)
ani = animation.FuncAnimation(fig, animate,
frames, interval=50, blit=True)
ani.save("witch.gif")
plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)