As the four words that make high school students go into cardiac arrest, they can be engraved for people after the entrance exams, so the definition is no longer repeated, and the standard equations are directly jacked up to the graphs, which are respectively
In Python, drawing moving pictures requires the use of thematplotlib
hit the nail on the headanimation
package, its calling method and the parameters to be used next are
ani = (fig, func, frames, interval)
included among thesefig
is the drawing window.func
is a plotting function whose return value is an image.frames
is the iteration parameter, and if it is an integer, the iteration parameter will berange(frames)
。
ellipses
For plotting purposes, the parametric equations of the ellipse are
Code for:
# These three packages will not be repeated later in the program # import numpy as np import as plt import as animation a,b,c = 5,3,4 fig = (figsize=(12,9)) ax = fig.add_subplot(autoscale_on=False, xlim=(-a,a),ylim=(-b,b)) () line, = ([],[],'o-',lw=2) trace, = ([],[],'-', lw=1) theta_text = (0.02,0.85,'',transform=) textTemplate = '''theta = %.1f°\n lenL = %.1f, lenR = %.1f\n lenL+lenR = %.1f''' xs,ys = [], [] def animate(i): if(i==0): () () theta = i*0.04 x = a*(theta) y = b*(theta) (x) (y) line.set_data([-c,x,c], [0,y,0]) trace.set_data(xs,ys) lenL = ((x+c)**2+y**2) lenR = ((x-c)**2+y**2) theta_text.set_text(textTemplate % (180*theta/, lenL, lenR, lenL+lenR)) return line, trace, theta_text ani = (fig, animate, 157, interval=5, blit=True) ("") ()
hyperbola
The parametric equation of the hyperbola is
Let a = 4 , b = 3 , c = 5 then the code is as follows
a,b,c = 4,3,5 fig = (figsize=(12,9)) ax = fig.add_subplot(autoscale_on=False, xlim=(-c,16),ylim=(-12,12)) () line, = ([],[],'o-',lw=2) trace, = ([],[],'-', lw=1) theta_text = (0.01,0.85,'', transform=) textTemplate = '''t = %.1f\n lenL = %.1f, lenR = %.1f\n lenL-lenR = %.1f''' xs,ys = [],[] def animate(t): if(t==-3): () () x = a*(t) y = b*(t) (x) (y) line.set_data([-c,x,c], [0,y,0]) trace.set_data(xs,ys) lenL = ((x+c)**2+y**2) lenR = ((x-c)**2+y**2) theta_text.set_text(textTemplate % (t, lenL, lenL, lenL-lenR)) return line, trace, theta_text frames = (-3,3,0.05) ani = (fig, animate, frames, interval=5, blit=True) ("") ()
parabola
import numpy as np import as plt import as animation a,b,c = 4,3,5 p = 1 fig = (figsize=(12,9)) ax = fig.add_subplot(autoscale_on=False, xlim=(-0.6,4.5),ylim=(-3,3)) () ([-p/2,-p/2],[-5,5],'-',lw=2) line, = ([],[],'o-',lw=2) trace, = ([],[],'-', lw=1) theta_text = (0.05,0.85,'', transform=) textTemplate = '''y = %.1f\n lenL = %.1f, lenF = %.1f\n lenL-lenF = %.1f''' xs,ys = [],[] def animate(y): if(y==-3): () () x = y**2/p/2 (x) (y) line.set_data([-p,x,p/2], [y,y,0]) trace.set_data(xs,ys) lenL = x+p/2 lenF = ((x-p/2)**2+y**2) theta_text.set_text(textTemplate % (y, lenL, lenF, lenL-lenF)) return line, trace, theta_text frames = (-3,3,0.1) ani = (fig, animate, frames, interval=5, blit=True) ("") ()
polar coordinate equation (math.)
The conic curve has the same expression in the polar coordinate system, i.e.
existmatplotlib
In this case, the polarized image needs to be passed through theprojection='polar'
to identify it with the code
p = 2 fig = (figsize=(12,9)) ax = fig.add_subplot(autoscale_on=False, projection='polar') ax.set_rlim(0,8) trace, = ([],[],'-', lw=1) theta_text = (0.05,0.95,'',transform=) textTemplate = 'e = %.1f\n' theta = (-3.1,3.2,0.1) def animate(e): rho = p/(1-e*(theta)) trace.set_data(theta,rho) theta_text.set_text(textTemplate % e) return trace, theta_text frames = (-2,2,0.1) ani = (fig, animate, frames, interval=100, blit=True) ("") ()
Above is Python using matplotlib to draw dynamic conic curve example of the details, more information about matplotlib to draw dynamic conic curve please pay attention to my other related articles!