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 Argument Description
options.times Array The array of control point times.
options.points Array The array of control points.
options.tangents Array <optional>
The array of tangents at each control point.
options.firstTangent Cartesian3 <optional>
The tangent of the curve at the first control point. If the tangent is not given, it will be estimated.
options.lastTangent Cartesian3 <optional>
The tangent of the curve at the last control point. If the tangent is not given, it will be estimated.
Throws:
Example
// Example 1.
// Create a natural cubic spline above the earth from Philadelphia to Los Angeles.
var spline = new HermiteSpline({
    times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],
    points : [
        new Cartesian3(1235398.0, -4810983.0, 4146266.0),
        new Cartesian3(1372574.0, -5345182.0, 4606657.0),
        new Cartesian3(-757983.0, -5542796.0, 4514323.0),
        new Cartesian3(-2821260.0, -5248423.0, 4021290.0),
        new Cartesian3(-2539788.0, -4724797.0, 3620093.0)
    ]
});

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

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

var spline = new HermiteSpline({
    times : times,
    points : points,
    tangents : tangents
});
See:
Source:

Members

:DeveloperError

Finds an index i in times such that the parameter time is in the interval [times[i], times[i + 1]].

<readonly> :Array

An array of Cartesian3 control points.

<readonly> :Array

An array of Cartesian3 tangents at each control point.

<readonly> :Array

An array of times for the control points.

Methods

Evaluates the curve at a given time.

Parameters:
Name Type Argument Description
time Number The time at which to evaluate the curve.
result Cartesian3 <optional>
The object onto which to store the result.
Throws:
  • DeveloperError : time is required.
  • DeveloperError : time must be in the range [t0, tn], where t0 is the first element in the array times and tn is the last element in the array times.
Returns:
Cartesian3 The modified result parameter or a new instance of the point on the curve at the given time.
Example
// spline above the earth from Philadelphia to Los Angeles
var spline = new HermiteSpline({
    times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],
    points : [
        new Cartesian3(1235398.0, -4810983.0, 4146266.0),
        new Cartesian3(1372574.0, -5345182.0, 4606657.0),
        new Cartesian3(-757983.0, -5542796.0, 4514323.0),
        new Cartesian3(-2821260.0, -5248423.0, 4021290.0),
        new Cartesian3(-2539788.0, -4724797.0, 3620093.0)
    ]
});

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