10 #ifndef G3D_SPLINEFUNC_H
11 #define G3D_SPLINEFUNC_H
41 template<
class XType,
class YType>
42 YType
linearSpline(
double x,
const XType* controlX,
const YType* controlY,
int numControl) {
46 if ((numControl == 1) || (x < controlX[0])) {
50 for (
int i = 1; i < numControl; ++i) {
51 if (x < controlX[i]) {
52 const double alpha = (double)(controlX[i] - x) / (controlX[i] - controlX[i - 1]);
53 return controlY[i] * (1 - alpha) + controlY[i - 1] * alpha;
58 return controlY[numControl - 1];
65 const YType* controlY,
70 t =
wrap(t, numPoints);
82 const YType& P0 = controlY[(i + 0) % numPoints];
83 const YType& P1 = controlY[(i + 1) % numPoints];
84 const YType& P2 = controlY[(i + 2) % numPoints];
85 const YType& P3 = controlY[(i + 3) % numPoints];
87 return 0.5 * ((2 * P1) +
89 (2*P0 - 5*P1 + 4*P2 - P3) * t*t +
90 (-P0 + 3*P1- 3*P2 + P3) * t*t*t);
110 int numPoints = controlY.
size();
YType linearSpline(double x, const XType *controlX, const YType *controlY, int numControl)
Definition: splinefunc.h:42
T * getCArray()
Definition: Array.h:256
Dynamic 1D array tuned for performance.
Definition: Array.h:95
int iFloor(double fValue)
Definition: g3dmath.h:603
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
#define debugAssert(exp)
Definition: debugAssert.h:160
int size() const
Definition: Array.h:430
YType cyclicCatmullRomSpline(double t, const YType *controlY, int numPoints)
Definition: splinefunc.h:63
G3D::int16 x
Definition: Vector2int16.h:37