Appearance
KBE3D / KBCore / Cesium / HermiteSpline
类: HermiteSpline
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 <code>points[i]</code> and <code>points[i + 1]</code>, the tangents at the points will be <code>outTangents[i]</code> and <code>inTangents[i]</code>, respectively.
示例
ts
// Create a G<sup>1</sup> continuous Hermite spline
const times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];
const 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)
]
});
const p0 = spline.evaluate(times[0]);参数
Object with the following properties:
参数
An array of strictly increasing, unit-less, floating-point times at each point. The values are in no way connected to the clock time. They are the parameterization for the curve.
参数
The array of control points.
参数
The array of incoming tangents at each control point.
参数
The array of outgoing tangents at each control point.
属性
times
readonlytimes:number[]
An array of times for the control points.
points
readonlypoints:Cartesian3[]
An array of control points.
inTangents
readonlyinTangents:Cartesian3[]
An array of incoming tangents at each control point.
outTangents
readonlyoutTangents:Cartesian3[]
An array of outgoing tangents at each control point.
方法
createC1()
staticcreateC1(options: {times:number[];points:Cartesian3[];tangents:Cartesian3[]; }):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 C<sup>1</sup>.
参数
options
Object with the following properties:
times
number[]
The array of control point times.
points
The array of control points.
tangents
The array of tangents at the control points.
返回
HermiteSpline
A hermite spline.
示例
ts
const 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
const tangents = new Array(points.length);
tangents[0] = new Cesium.Cartesian3(1125196, -161816, 270551);
const temp = new Cesium.Cartesian3();
for (let 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);
const spline = Cesium.HermiteSpline.createC1({
times : times,
points : points,
tangents : tangents
});createNaturalCubic()
staticcreateNaturalCubic(options: {times:number[];points:Cartesian3[]; }):HermiteSpline|LinearSpline
Creates a natural cubic spline. The tangents at the control points are generated to create a curve in the class C<sup>2</sup>.
参数
options
Object with the following properties:
times
number[]
The array of control point times.
points
The array of control points.
返回
HermiteSpline | LinearSpline
A hermite spline, or a linear spline if less than 3 control points were given.
示例
ts
// Create a natural cubic spline above the earth from Philadelphia to Los Angeles.
const 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)
]
});createClampedCubic()
staticcreateClampedCubic(options: {times:number[];points:number[] |Cartesian3[];firstTangent:Cartesian3;lastTangent:Cartesian3; }):HermiteSpline|LinearSpline
Creates a clamped cubic spline. The tangents at the interior control points are generated to create a curve in the class C<sup>2</sup>.
参数
options
Object with the following properties:
times
number[]
The array of control point times.
points
number[] | Cartesian3[]
The array of control points.
firstTangent
The outgoing tangent of the first control point.
lastTangent
The incoming tangent of the last control point.
返回
HermiteSpline | LinearSpline
A hermite spline, or a linear spline if less than 3 control points were given.
示例
ts
// Create a clamped cubic spline above the earth from Philadelphia to Los Angeles.
const 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)
});findTimeInterval()
findTimeInterval(
time:number):number
Finds an index <code>i</code> in <code>times</code> such that the parameter <code>time</code> is in the interval <code>[times[i], times[i + 1]]</code>.
参数
time
number
The time.
返回
number
The index for the element at the start of the interval.
wrapTime()
wrapTime(
time:number):number
Wraps the given time to the period covered by the spline.
参数
time
number
The time.
返回
number
The time, wrapped around to the updated animation.
clampTime()
clampTime(
time:number):number
Clamps the given time to the period covered by the spline.
参数
time
number
The time.
返回
number
The time, clamped to the animation period.
evaluate()
evaluate(
time:number,result?:Cartesian3):Cartesian3
Evaluates the curve at a given time.
参数
time
number
The time at which to evaluate the curve.
result?
The object onto which to store the result.
返回
The modified result parameter or a new instance of the point on the curve at the given time.
构造函数
构造函数
new HermiteSpline(
options: {times:number[];points:Cartesian3[];inTangents:Cartesian3[];outTangents:Cartesian3[]; }):HermiteSpline
参数
options
times
number[]
points
inTangents
outTangents
返回
HermiteSpline
