Hermite 样条是一种三次插值样条。必须为每个控制点定义点、入切线、出切线和时间。
出切线为点 [0, n - 2] 定义,入切线为点 [1, n - 1] 定义。
例如,当插值
points[i] 和 points[i + 1] 之间的曲线段时,
点处的切线将分别为 outTangents[i] 和 inTangents[i]。
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
Throws:
-
DeveloperError : points.length 必须大于或等于 2。
-
DeveloperError : times.length 必须等于 points.length。
-
DeveloperError : inTangents 和 outTangents 的长度必须等于 points.length - 1。
-
DeveloperError : inTangents 和 outTangents 必须与 points 类型相同。
Example:
// 创建 G<sup>1</sup> 连续的 Hermite 样条
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>
每个控制点处的入切线数组。
readonly outTangents : Array.<Cartesian3>
每个控制点处的出切线数组。
readonly points : Array.<Cartesian3>
控制点数组。
控制点的时间数组。
Methods
static Cesium.HermiteSpline.createC1(options) → HermiteSpline
创建一个每个控制点处切线相同的样条。曲线保证至少在 C1 类中。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
Returns:
Hermite 样条。
Throws:
-
DeveloperError : 必须提供 points、times 和 tangents。
-
DeveloperError : points.length 必须大于或等于 2。
-
DeveloperError : times、points 和 tangents 必须具有相同的长度。
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)
];
// 添加切线
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
创建钳制三次样条。内部控制点处的切线会自动生成,以创建 C2 类曲线。
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
Returns:
Hermite 样条,如果控制点少于 3 个则返回线性样条。
Throws:
-
DeveloperError : 必须提供 points、times、firstTangent 和 lastTangent。
-
DeveloperError : points.length 必须大于或等于 2。
-
DeveloperError : times.length 必须等于 points.length。
-
DeveloperError : firstTangent 和 lastTangent 必须与 points 类型相同。
Example:
// 在地球上方从费城到洛杉矶创建钳制三次样条。
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
创建自然三次样条。控制点处的切线会自动生成,以创建 C2 类曲线。
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
Returns:
Hermite 样条,如果控制点少于 3 个则返回线性样条。
Throws:
-
DeveloperError : 必须提供 points 和 times。
-
DeveloperError : points.length 必须大于或等于 2。
-
DeveloperError : times.length 必须等于 points.length。
Example:
// 在地球上方从费城到洛杉矶创建自然三次样条。
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)
]
});
将给定时间钳制到样条覆盖的周期内。
| Name | Type | Description |
|---|---|---|
time |
number | 时间。 |
Returns:
钳制到动画周期的时间。
evaluate(time, result) → Cartesian3
在给定时间评估曲线。
| Name | Type | Description |
|---|---|---|
time |
number | 评估曲线的时间。 |
result |
Cartesian3 | optional 存储结果的对象。 |
Returns:
修改后的结果参数,或给定时间曲线上的新点实例。
Throws:
在
times 中查找索引 i,使得参数
time 位于区间 [times[i], times[i + 1]] 内。
| Name | Type | Description |
|---|---|---|
time |
number | 时间。 |
Returns:
区间起始元素的索引。
Throws:
将给定时间环绕到样条覆盖的周期内。
| Name | Type | Description |
|---|---|---|
time |
number | 时间。 |
Returns:
环绕更新后的动画时间。
