Skip to content

Instantly share code, notes, and snippets.

@lecion
Created May 28, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lecion/ba1966248024411581e066f424a8268d to your computer and use it in GitHub Desktop.
Save lecion/ba1966248024411581e066f424a8268d to your computer and use it in GitHub Desktop.
Cubic-bezier implementation.
float bezier(float t, float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y,
float p3_x, float p3_y) {
float c_x = 3 * (p1_x - p0_x);
float b_x = 3 * (p2_x - p1_x) - c_x;
float a_x = p3_x - p0_x - c_x - b_x;
float c_y = 3 * (p1_y - p0_y);
float b_y = 3 * (p2_y - p1_y) - c_y;
float a_y = p3_y - p0_y - c_y - b_y;
float x = (a_x * powf(t, 3)) + (b_x * powf(t, 2)) + (c_x * t) + p0_x;
float y = (a_y * powf(t, 3)) + (b_y * powf(t, 2)) + (c_y * t) + p0_y;
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment