Created
May 28, 2018 13:17
-
-
Save lecion/ba1966248024411581e066f424a8268d to your computer and use it in GitHub Desktop.
Cubic-bezier implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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