We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to make a parabole
Page Index Toggle Pages: 1
how to make a parabole (Read 353 times)
how to make a parabole
Feb 23rd, 2009, 6:33pm
 
Hey everyone,

i was wondering how to make a parabole.
Not as a graphic, but as a formule.
Because i want to know the x,y positions,
to read the pixels of the image like a parabole.

The same question goes for the vertex method.
You can make a bended line, but i want to know the x/y's

thanks
Re: how to make a parabole
Reply #1 - Feb 23rd, 2009, 7:35pm
 
The standard definition of a parabola is any curve of the form:

y = k*x^2 + c

Obviously, you can scale and rotate the coordinate system so that you get parabolas at different orientations.  But for your question, of how to know the exact coordinates of the points in the parabola, you just take any value 'x' and compute the value 'y' from the above formula.  The parameters 'k' and 'c' control how wide/narrow the parabola is, and how much it is shifted up or down relative to the x-axis.

Quote:
void setup()
{
  size(400,400);
  background(0);
  stroke(255);
  noLoop();
}

void draw()
{
  // set up the coordinate axes:
  translate(width/2,height/2);
  scale(1, -1);
  
  line(0, 200, 0, -200);
  line(-200, 0, 200, 0);
  
  // draw three random parabolas
  for(int i = 0; i < 3; i++)
  {
    float k = random(-.1, .1);
    float c = random(-50, 50);
    
    for(float x = -200; x < 200; x++)
    {
      float y = k*x*x + c;
      point(x,y);
    }
  }
}

void mousePressed()
{
  background(0);
  redraw();
}

Page Index Toggle Pages: 1