Finding the handles for Bezier vertexes of complex functions

edited February 2018 in Questions about Code

I have this code here where I create an array for x and y coordinates for a complex sine cosine function. I then use the beginShape function and create bezierVertexes for each x and y coordinate. The problem is that I don't know what the coordinates are going to be for each of the handles and it seems impossible to try and hardcode every single handle coordinate. Is there any sort of formula to determine what the handles are going to be for my function?

float[] x; 
float[] y;
float amplitude = 75.0;

void setup()
{
  size(1200,1200);
}

void draw()
{
  x = new float[5000];
  x[0]=0;
  for(int i=1; i<x.length; i++)
  {
   x[i]=x[i-1]+PI; 
  }
  y = new float[x.length];
  translate(0,height/2);
  beginShape();
  vertex(0,0);
  for(int j=0; j<x.length; j++)
  {
    y[j]=amplitude*pow(sin(.025*x[j]),3)*cos(.025*x[j]);
    stroke(0);
    strokeWeight(1);
    noFill();
    if(j==0)
    {
      vertex(x[j],y[j]);
    }
    else
    {
      bezierVertex(x[j-1],y[j-1],x[j],y[j],x[j],y[j]);
    }

  }
  endShape();

}
Tagged:

Answers

Sign In or Register to comment.