Skip to content

Commit

Permalink
feat: bezier core math
Browse files Browse the repository at this point in the history
  • Loading branch information
DoggyXomaX committed Aug 3, 2024
0 parents commit 281bd5e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/bezier_core.c
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions src/bezier_core.h
Original file line number Diff line number Diff line change
@@ -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__

0 comments on commit 281bd5e

Please sign in to comment.