Hermite 样条是三次插值样条。必须为每个控制点定义点、传入切线、传出切线和时间。出线切线是为点 [0, n - 2] 定义的,入线切线是为点 [1, n - 1] 定义的。例如,当在之间插入一段曲线时 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.
| 名称 Name | 类型 Type | 说明 Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
抛出: Throws:
-
DeveloperError : points.length must be greater than or equal to 2.
-
DeveloperError :times.length必须等于points.length。 : times.length must be equal to points.length.
-
DeveloperError :inTangents 和outTangents 的长度必须等于points.length - 1。 : inTangents and outTangents must have a length equal to points.length - 1.
-
DeveloperError :inTangents 和 outTangents 必须与点类型相同。 : inTangents and outTangents must be of the same type as points.
示例: Example:
// 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]);
另见: See:
成员 Members
readonly inTangents : Array.<Cartesian3>
每个控制点处的传入切线数组。 An array of incoming tangents at each control point.
readonly outTangents : Array.<Cartesian3>
每个控制点处的传出切线数组。 An array of outgoing tangents at each control point.
readonly points : Array.<Cartesian3>
控制点数组。 An array of control points.
控制点的时间数组。 An array of times for the control points.
方法 Methods
static Cesium.HermiteSpline.createC1(options) → HermiteSpline
创建每个控制点处的切线相同的样条线。曲线保证至少在C级 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.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
返回: Returns:
埃尔米特样条。 A hermite spline.
抛出: Throws:
-
DeveloperError : points, times and tangents are required.
-
DeveloperError : points.length must be greater than or equal to 2.
-
DeveloperError : times, points and tangents must have the same length.
示例: Example:
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
});
static Cesium.HermiteSpline.createClampedCubic(options) → HermiteSpline|LinearSpline
创建夹紧三次样条。生成内部控制点处的切线以创建 C 类曲线 Creates a clamped cubic spline. The tangents at the interior control points are generated to create a curve in the class C2.
| 名称 Name | 类型 Type | 说明 Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
返回: Returns:
如果给出的控制点少于 3 个,则使用埃尔米特样条曲线或线性样条曲线。 A hermite spline, or a linear spline if less than 3 control points were given.
抛出: Throws:
-
DeveloperError :点、时间、firstTangent 和lastTangent 为必填项。 : points, times, firstTangent and lastTangent are required.
-
DeveloperError : points.length must be greater than or equal to 2.
-
DeveloperError :times.length必须等于points.length。 : times.length must be equal to points.length.
-
DeveloperError :firstTangent 和lastTangent 必须与点类型相同。 : firstTangent and lastTangent must be of the same type as points.
示例: Example:
// 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)
});
static Cesium.HermiteSpline.createNaturalCubic(options) → HermiteSpline|LinearSpline
创建自然三次样条。生成控制点处的切线以创建 C 类曲线 Creates a natural cubic spline. The tangents at the control points are generated to create a curve in the class C2.
| 名称 Name | 类型 Type | 说明 Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
返回: Returns:
如果给出的控制点少于 3 个,则使用埃尔米特样条曲线或线性样条曲线。 A hermite spline, or a linear spline if less than 3 control points were given.
抛出: Throws:
-
DeveloperError : 需要点数和时间。 : points and times are required.
-
DeveloperError : points.length must be greater than or equal to 2.
-
DeveloperError :times.length必须等于points.length。 : times.length must be equal to points.length.
示例: Example:
// 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)
]
});
将给定时间限制为样条线覆盖的时间段。 Clamps the given time to the period covered by the spline.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
time |
number | 时间。 The time. |
返回: Returns:
时间,固定在动画期间。 The time, clamped to the animation period.
evaluate(time, result) → Cartesian3
评估给定时间的曲线。 Evaluates the curve at a given time.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
time |
number | 评估曲线的时间。 The time at which to evaluate the curve. |
result |
Cartesian3 | 可选 optional 用于存储结果的对象。 The object onto which to store the result. |
返回: Returns:
修改后的结果参数或给定时间曲线上点的新实例。 The modified result parameter or a new instance of the point on the curve at the given time.
抛出: Throws:
-
DeveloperError : 时间必须在范围内 : time must be in the range
[t0, tn], 其中 , wheret0是数组中的第一个元素 is the first element in the arraytimesandtn是数组中的最后一个元素 is the last element in the arraytimes.
查找索引 Finds an index
i in times 这样参数 such that the parameter
time 是在区间内 is in the interval [times[i], times[i + 1]].
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
time |
number | 时间。 The time. |
返回: Returns:
间隔开始处的元素的索引。 The index for the element at the start of the interval.
抛出: Throws:
-
DeveloperError : 时间必须在范围内 : time must be in the range
[t0, tn], 其中 , wheret0是数组中的第一个元素 is the first element in the arraytimesandtn是数组中的最后一个元素 is the last element in the arraytimes.
将给定时间包裹到样条线覆盖的时间段。 Wraps the given time to the period covered by the spline.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
time |
number | 时间。 The time. |
返回: Returns:
时间,围绕着更新的动画。 The time, wrapped around to the updated animation.
