Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created December 29, 2011 21:22
Show Gist options
  • Save fjolnir/1536261 to your computer and use it in GitHub Desktop.
Save fjolnir/1536261 to your computer and use it in GitHub Desktop.
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