expo-processing/Bezier.pde

13 lines
636 B
Plaintext
Executable File

int []quadraticBezier(int p0_x, int p0_y, int p1_x, int p1_y, int p2_x, int p2_y, float t)
{
int []pf = { int(pow(1 - t, 2) * p0_x + (1 - t) * 2 * t * p1_x + t * t * p2_x),
int(pow(1 - t, 2) * p0_y + (1 - t) * 2 * t * p1_y + t * t * p2_y) };
return (pf);
}
C_point cubicBezier(C_point p0, C_point p1, C_point p2, C_point p3, float t)
{
return(new C_point(pow(1 - t, 3) * p0.x + pow(1 - t, 2) * 3 * t * p1.x + (1 - t) * 3 * t * t * p2.x + t * t * t * p3.x,
pow(1 - t, 3) * p0.y + pow(1 - t, 2) * 3 * t * p1.y + (1 - t) * 3 * t * t * p2.y + t * t * t * p3.y));
}