Created
December 29, 2011 21:22
-
-
Save fjolnir/1536261 to your computer and use it in GitHub Desktop.
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
static vec2_t bezier_firstDerivative(bezier_t curve, float t) | |
{ | |
vec2_t out; | |
vec3_t derivControlPoints[3]; | |
derivControlPoints[0] = vec3_sub(curve.controlPoints[1], curve.controlPoints[0]); | |
derivControlPoints[1] = vec3_sub(curve.controlPoints[2], curve.controlPoints[1]); | |
derivControlPoints[2] = vec3_sub(curve.controlPoints[3], curve.controlPoints[2]); | |
float mt = 1.0f - t; | |
float coef0 = powf(mt, 2.0f); | |
float coef1 = 2.0f * mt * t; | |
float coef2 = powf(t, 2.0f); | |
vec3_t p0 = vec3_scalarMul(derivControlPoints[0], coef0); | |
vec3_t p1 = vec3_scalarMul(derivControlPoints[1], coef1); | |
vec3_t p2 = vec3_scalarMul(derivControlPoints[2], coef2); | |
out = vec3_add(p0, vec3_add(p1, p2)); | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment