Draw a parabola (computer python): Difference between revisions

From wikiluntti
(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...")
 
 
Line 28: Line 28:
plt.plot(xx,yy)
plt.plot(xx,yy)
</syntaxhighlight>
</syntaxhighlight>
Back to [[Draw a parabola using a pen attached to a robot]].

Latest revision as of 19:01, 16 October 2020

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)

Back to Draw a parabola using a pen attached to a robot.