HermiteSpline

HermiteSpline

new

A Hermite spline is a cubic interpolating spline. Positions, tangents, and times must be defined for each control point. If no tangents are specified by the control points, the end and interior tangents are generated, creating a natural cubic spline. If the only tangents specified are at the end control points, the interior tangents will be generated as well, creating a clamped cubic spline. Otherwise, it is assumed that each control point defines a tangent at that point. Natural and clamped cubic splines are in the class C2.

Parameters:
Name Type Description
controlPoints Array An array, of at least length 3, of objects with point, time, and tangent properties.
Throws:
Example
// Example 1.
// Create a natural cubic spline above the earth from Philadelphia to Los Angeles.
var controlPoints = [
    {point: new Cartesian3(1235398.0, -4810983.0, 4146266.0), time: 0.0},
    {point: new Cartesian3(1372574.0, -5345182.0, 4606657.0), time: 1.5},
    {point: new Cartesian3(-757983.0, -5542796.0, 4514323.0), time: 3.0},
    {point: new Cartesian3(-2821260.0, -5248423.0, 4021290.0), time: 4.5},
    {point: new Cartesian3(-2539788.0, -4724797.0, 3620093.0), time: 6.0}
];
var spline = new HermiteSpline(controlPoints);

// Example 2.
// Create a Catmull-Rom spline above the earth from Philadelphia to Los Angeles.
var controlPoints = [
    {point: new Cartesian3(1235398.0, -4810983.0, 4146266.0), time: 0.0},
    {point: new Cartesian3(1372574.0, -5345182.0, 4606657.0), time: 1.5},
    {point: new Cartesian3(-757983.0, -5542796.0, 4514323.0), time: 3.0},
    {point: new Cartesian3(-2821260.0, -5248423.0, 4021290.0), time: 4.5},
    {point: new Cartesian3(-2539788.0, -4724797.0, 3620093.0), time: 6.0}
];

// Add tangents
controlPoints[0].tangent = new Cartesian3(1125196, -161816, 270551);
for (var i = 1; i < controlPoints.length - 1; ++i) {
    controlPoints[i].tangent = controlPoints[i + 1].point.subtract(controlPoints[i - 1].point).multiplyByScalar(0.5);
}
controlPoints[controlPoints.length - 1].tangent = new Cartesian3(1165345, 112641, 47281);

var spline = new HermiteSpline(controlPoints);
See:
Source:

Methods

Evaluates the curve at a given time.

Parameters:
Name Type Description
time Number The time at which to evaluate the curve.
Throws:
  • DeveloperError : time is required.
  • DeveloperError : time must be in the range [a0, an], where a0 and an are the time properties of first and last elements in the array given during construction, respectively.
Returns:
Cartesian3 The point on the curve at the given time.
Example
// spline above the earth from Philadelphia to Los Angeles
var controlPoints = [
    {point: new Cartesian3(1235398.0, -4810983.0, 4146266.0), time: 0.0},
    {point: new Cartesian3(1372574.0, -5345182.0, 4606657.0), time: 1.5},
    {point: new Cartesian3(-757983.0, -5542796.0, 4514323.0), time: 3.0},
    {point: new Cartesian3(-2821260.0, -5248423.0, 4021290.0), time: 4.5},
    {point: new Cartesian3(-2539788.0, -4724797.0, 3620093.0), time: 6.0}
];
var spline = new HermiteSpline(controlPoints);

// some position above Los Angeles
var position = spline.evaluate(5.0);

Returns the array of control points.

Returns:
Array The array of control points.