I need help creating a hypotrochoid in Processing

Viewed 94

I need help creating a hypotrochoid. Starting with three values (inner radius, outer radius, and distance), I need to draw a shape by computing a sequence of points, drawing straight lines from point, to point, to point, etc.

I started a little but I'm now completely lost and don't really know what I'm doing. Anything will help thank you.

Hypotrochoid: https://en.wikipedia.org/wiki/Hypotrochoid

float xpos,ypos,r,d,R,t,a,b;
int centerX,centerY,center;

void setup() {
 size(600,600);
 centerX = width/2;
 centerY = height/2;
 ellipse(300, 300, 300, 300);
 t = 25;
 a = 10;
 b = 5;

}

void draw(){
xpos=(a-b)*cos(t)+h*cos(((a-b)/b)*t);
ypos=(a-b)*sin(t)+h*sin(((a-b)/b)*t);
}
1 Answers

There is a problem in your formula when you calculate the ypos:

ypos=(a-b)*sin(t)+h*sin(((a-b)/b)*t);

ypos=(a-b)*sin(t) - h*sin(((a-b)/b)*t);

Calculate the angle t as a function of frameCount and draw a point at each coordinate:

int centerX, centerY;
float a, b, h;

void setup() {
   size(600,600);
   centerX = width/2;
   centerY = height/2;
   a = 100;
   b = 60;
   h = 100;
}

void draw(){  
    float t = frameCount * TWO_PI / 360;
    float x = (a-b)*cos(t) + h*cos((a-b)/b*t) + centerX;
    float y = (a-b)*sin(t) - h*sin((a-b)/b*t) + centerY;
    point(x, y);
}

Related