Home > Software design >  Parabola in Processing
Parabola in Processing

Time:03-28

I was transferring tasks from my maths textbook to Processing. One of the problems required the use of a parabola. I decided to write it as a Bézier curve, wrote the code, but something didn't work. Could anyone please explain to me what I did wrong here?

The code:

def setup():

    background(255,255,255)

    size(800,800)

    rectMode(CENTER)

    line(400,0,400,800)

    line(0,400,800,400)

    #B 0 to know the start and the end points

    a=1

    x=3

    b=0

    c=10

    translate(width/2, height/2)

    noFill()

    beginShape()

    #Parabola formula

    y=-(a*x*x b*x c)

    #X of the point of the symetry

    Sx=(-b)/(2*a)

    #Y of the point of the symetry

    Sy=-(a*Sx*Sx b*Sx c)

    #Derivative

    Ny=-(800 b)

    #Y of the starting point

    By=-(a*400*400-b*400 c)

    #Y of the end point

    Ey=-(a*400*400 b*400 c)

    #Y3 Y4

    Ty=Ny*(x 400)-By

    bezier(-400,By,Sx,Ty,400,Ey,Sx,Ty)

    endShape()

    noFill()

    beginShape()

    for i in range (-400,400):

        x=i

        y=-i

        vertex(x,y)

    endShape()

(It had to be an 800x800 coordinate plane, a parabola and a straight line.)

CodePudding user response:

Your resulting y coordinates are way too high for the

  • Related