new HermiteSpline(options)
A Hermite spline is a cubic interpolating spline. Points, incoming tangents, outgoing tangents, and times
must be defined for each control point. The outgoing tangents are defined for points [0, n - 2] and the incoming
tangents are defined for points [1, n - 1]. For example, when interpolating a segment of the curve between
points[i]
and
points[i + 1]
, the tangents at the points will be outTangents[i]
and inTangents[i]
,
respectively.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Object with the following properties:
Properties
|
Throws:
-
-
points.length must be greater than or equal to 2.
- Type
- DeveloperError
-
-
-
times.length must be equal to points.length.
- Type
- DeveloperError
-
-
-
inTangents and outTangents must have a length equal to points.length - 1.
- Type
- DeveloperError
-
Example
// Create a G<sup>1</sup> continuous Hermite spline
var times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];
var spline = new Cesium.HermiteSpline({
times : times,
points : [
new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),
new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),
new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),
new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),
new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)
],
outTangents : [
new Cesium.Cartesian3(1125196, -161816, 270551),
new Cesium.Cartesian3(-996690.5, -365906.5, 184028.5),
new Cesium.Cartesian3(-2096917, 48379.5, -292683.5),
new Cesium.Cartesian3(-890902.5, 408999.5, -447115)
],
inTangents : [
new Cesium.Cartesian3(-1993381, -731813, 368057),
new Cesium.Cartesian3(-4193834, 96759, -585367),
new Cesium.Cartesian3(-1781805, 817999, -894230),
new Cesium.Cartesian3(1165345, 112641, 47281)
]
});
var p0 = spline.evaluate(times[0]);
Members
(readonly) inTangents :Array.<Cartesian3>
An array of
Cartesian3
incoming tangents at each control point.
Type:
- Array.<Cartesian3>
- Source:
(readonly) outTangents :Array.<Cartesian3>
An array of
Cartesian3
outgoing tangents at each control point.
Type:
- Array.<Cartesian3>
- Source:
(readonly) points :Array.<Cartesian3>
An array of
Cartesian3
control points.
Type:
- Array.<Cartesian3>
- Source:
(readonly) times :Array.<Number>
An array of times for the control points.
Type:
- Array.<Number>
- Source:
Methods
(static) createC1(options) → {HermiteSpline}
Creates a spline where the tangents at each control point are the same.
The curves are guaranteed to be at least in the class C1.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Object with the following properties:
Properties
|
- Source:
Throws:
-
-
points, times and tangents are required.
- Type
- DeveloperError
-
-
-
points.length must be greater than or equal to 2.
- Type
- DeveloperError
-
-
-
times, points and tangents must have the same length.
- Type
- DeveloperError
-
Returns:
A hermite spline.
- Type
- HermiteSpline
Example
var points = [
new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),
new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),
new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),
new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),
new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)
];
// Add tangents
var tangents = new Array(points.length);
tangents[0] = new Cesium.Cartesian3(1125196, -161816, 270551);
var temp = new Cesium.Cartesian3();
for (var i = 1; i < tangents.length - 1; ++i) {
tangents[i] = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(points[i + 1], points[i - 1], temp), 0.5, new Cesium.Cartesian3());
}
tangents[tangents.length - 1] = new Cesium.Cartesian3(1165345, 112641, 47281);
var spline = Cesium.HermiteSpline.createC1({
times : times,
points : points,
tangents : tangents
});
(static) createClampedCubic(options) → {HermiteSpline|LinearSpline}
Creates a clamped cubic spline. The tangents at the interior control points are generated
to create a curve in the class C2.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Object with the following properties:
Properties
|
- Source:
Throws:
-
-
points, times, firstTangent and lastTangent are required.
- Type
- DeveloperError
-
-
-
points.length must be greater than or equal to 2.
- Type
- DeveloperError
-
-
-
times.length must be equal to points.length.
- Type
- DeveloperError
-
Returns:
A hermite spline or a linear spline if less than 3 control points were given.
- Type
- HermiteSpline | LinearSpline
Example
// Create a clamped cubic spline above the earth from Philadelphia to Los Angeles.
var spline = Cesium.HermiteSpline.createClampedCubic({
times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],
points : [
new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),
new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),
new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),
new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),
new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)
],
firstTangent : new Cesium.Cartesian3(1125196, -161816, 270551),
lastTangent : new Cesium.Cartesian3(1165345, 112641, 47281)
});
(static) createNaturalCubic(options) → {HermiteSpline|LinearSpline}
Creates a natural cubic spline. The tangents at the control points are generated
to create a curve in the class C2.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Object with the following properties:
Properties
|
- Source:
Throws:
-
-
points and times are required.
- Type
- DeveloperError
-
-
-
points.length must be greater than or equal to 2.
- Type
- DeveloperError
-
-
-
times.length must be equal to points.length.
- Type
- DeveloperError
-
Returns:
A hermite spline or a linear spline if less than 3 control points were given.
- Type
- HermiteSpline | LinearSpline
Example
// Create a natural cubic spline above the earth from Philadelphia to Los Angeles.
var spline = Cesium.HermiteSpline.createNaturalCubic({
times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],
points : [
new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),
new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),
new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),
new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),
new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)
]
});
evaluate(time, resultopt) → {Cartesian3}
Evaluates the curve at a given time.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
time |
Number | The time at which to evaluate the curve. | |
result |
Cartesian3 |
<optional> |
The object onto which to store the result. |
- Source:
Throws:
-
time must be in the range
[t0, tn]
, wheret0
is the first element in the arraytimes
andtn
is the last element in the arraytimes
. - Type
- DeveloperError
Returns:
The modified result parameter or a new instance of the point on the curve at the given time.
- Type
- Cartesian3
findTimeInterval(time) → {Number}
Finds an index
i
in times
such that the parameter
time
is in the interval [times[i], times[i + 1]]
.
Parameters:
Name | Type | Description |
---|---|---|
time |
Number | The time. |
- Source:
Throws:
-
time must be in the range
[t0, tn]
, wheret0
is the first element in the arraytimes
andtn
is the last element in the arraytimes
. - Type
- DeveloperError
Returns:
The index for the element at the start of the interval.
- Type
- Number