Friday, 30 March 2012

Bezier Curve template

Sometimes you just want some simple code you can drop in to do bezier curves:

Templated Bezier function:

static inline float CR40( float t ) { return 0.5f*(2*t*t-t*t*t-t); }
static inline float CR41( float t ) { return 0.5f*(2.0f-5*t*t+3*t*t*t); }
static inline float CR42( float t ) { return 0.5f*(4*t*t+t-3*t*t*t); }
static inline float CR43( float t ) { return 0.5f*(t*t*t-t*t); }
template<typename T>
T CRBez4( T a, T b, T c, T d, float t )
return CR40(t) * a + CR41(t) * b + CR42(t) * c + CR43(t) * d;


Well, now you can. Here's some rather old code I found, and recently reused.
Post a Comment