Draw a parabola (computer python)

From wikiluntti
Revision as of 18:58, 16 October 2020 by Mol (talk | contribs) (Created page with "== Introduction == The script is used to plot and test the code for drawing the parabola using a robot <syntaxhighlight lang="python"> import matplotlib.pyplot as plt import...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

The script is used to plot and test the code for drawing the parabola using a robot

import matplotlib.pyplot as plt
import math

a = -0.1
x,y = [], []
for i in range(-5,1):
    y1 = i
    y0 = i-1
    Dy = y1-y0
    Dx = math.sqrt(y1/a) - math.sqrt(y0/a)
    alpha = math.atan(Dx/Dy)/3.14159*180    #In degrees
    l = math.sqrt(Dy**2 + Dx**2)
    print( alpha, l )
    x.append( math.sqrt(y1/a) )
    y.append( y1 )
        
# Plot the true parabola using Numpy.
from numpy import *
xx=linspace(0,x[1],5000)
yy=a*xx**2

plt.plot(x,y, 'o-')
plt.plot(xx,yy)