diff --git a/src/bezier_core.c b/src/bezier_core.c new file mode 100644 index 0000000..46550aa --- /dev/null +++ b/src/bezier_core.c @@ -0,0 +1,43 @@ +#include "bezier_core.h" + +double linear(const double t, const double p0, const double p1) { + return p0 + (p1 - p0) * t; +} + +double quadratic(const double t, const double p0, const double p1, const double p2) { + const double at = 1 - t; + return + at * at * p0 + + 2 * at * t * p1 + + t * t * p2; +} + +double cubic(const double t, const double p0, const double p1, const double p2, const double p3) { + const double at = 1 - t; + return + at * at * at * p0 + + 3 * at * at * t * p1 + + 3 * at * t * t * p2 + + t * t * t * p3; +} + +float linearf(const float t, const float p0, const float p1) { + return p0 + (p1 - p0) * t; +} + +float quadraticf(const float t, const float p0, const float p1, const float p2) { + const float at = 1 - t; + return + at * at * p0 + + 2 * at * t * p1 + + t * t * p2; +} + +float cubicf(const float t, const float p0, const float p1, const float p2, const float p3) { + const float at = 1 - t; + return + at * at * at * p0 + + 3 * at * at * t * p1 + + 3 * at * t * t * p2 + + t * t * t * p3; +} diff --git a/src/bezier_core.h b/src/bezier_core.h new file mode 100644 index 0000000..4c38bf7 --- /dev/null +++ b/src/bezier_core.h @@ -0,0 +1,12 @@ +#ifndef __HMAH_BEZIER_CORE_H__ +#define __HMAH_BEZIER_CORE_H__ + +double linear(double t, double p0, double p1); +double quadratic(double t, double p0, double p1, double p2); +double cubic(double t, double p0, double p1, double p2, double p3); + +float linearf(float t, float p0, float p1); +float quadraticf(float t, float p0, float p1, float p2); +float cubicf(float t, float p0, float p1, float p2, float p3); + +#endif // __HMAH_BEZIER_CORE_H__ \ No newline at end of file