Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
/** | /** | ||||
* Catmull-Rom spline. | |||||
* Interpolates the value of a point that is located between four known equidistant points with given values by | * Interpolates the value of a point that is located between four known equidistant points with given values by | ||||
* constructing a polynomial of degree three that goes through all points. | * constructing a polynomial of degree three that goes through all points. | ||||
* Computes a cardinal or Catmull-Rom spline. | |||||
* | * | ||||
* @param {Number} tension - determines the geometry of the curve, between 0 (tight curve) and 1 (smooth curve). | * @param {Number} tension - determines how sharply the curve bends at the given points. | ||||
* Depending on the tension, the spline is called uniform (0), centripetal (0.5) or chordal (1). | |||||
* @param {Number} x - Location of the point to interpolate, relative to p1 | * @param {Number} x - Location of the point to interpolate, relative to p1 | ||||
*/ | */ | ||||
function cubicInterpolation(tension, x, p0, p1, p2, p3) | function cubicInterpolation(tension, x, p0, p1, p2, p3) | ||||
{ | { | ||||
let P = -tension * p0 + (2 - tension) * p1 + (tension - 2) * p2 + tension * p3; | let P = -tension * p0 + (2 - tension) * p1 + (tension - 2) * p2 + tension * p3; | ||||
let Q = 2 * tension * p0 + (tension - 3) * p1 + (3 - 2 * tension) * p2 - tension * p3; | let Q = 2 * tension * p0 + (tension - 3) * p1 + (3 - 2 * tension) * p2 - tension * p3; | ||||
let R = -tension * p0 + tension * p2; | let R = -tension * p0 + tension * p2; | ||||
let S = p1; | let S = p1; | ||||
Show All 27 Lines |
Wildfire Games · Phabricator