English中文

HermiteSpline

new Cesium.HermiteSpline(options)

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:
名称 Name 类型 Type 说明 Description
times Array.<number> 每个点的严格递增、无单位浮点时间数组。这些值与时钟时间没有任何关系。它们是曲线的参数化。 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.
points Array.<Cartesian3> 控制点数组。 The array of control points.
inTangents Array.<Cartesian3> 每个控制点处的传入切线数组。 The array of incoming tangents at each control point.
outTangents Array.<Cartesian3> 每个控制点处的出射切线数组。 The array of outgoing tangents at each control point.
抛出: 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.
控制点数组。 An array of control points.

readonly times : Array.<number>

控制点的时间数组。 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:
名称 Name 类型 Type 说明 Description
times Array.<number> 控制点时间数组。 The array of control point times.
points Array.<Cartesian3> 控制点数组。 The array of control points.
tangents Array.<Cartesian3> 控制点处的切线数组。 The array of tangents at the control points.
返回: Returns:
埃尔米特样条。 A hermite spline.
抛出: Throws:
示例: 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:
名称 Name 类型 Type 说明 Description
times Array.<number> 控制点时间数组。 The array of control point times.
points Array.<number> | Array.<Cartesian3> 控制点数组。 The array of control points.
firstTangent Cartesian3 第一个控制点的出线切线。 The outgoing tangent of the first control point.
lastTangent Cartesian3 最后一个控制点的入切线。 The incoming tangent of the last control point.
返回: 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:
名称 Name 类型 Type 说明 Description
times Array.<number> 控制点时间数组。 The array of control point times.
points Array.<Cartesian3> 控制点数组。 The array of control points.
返回: 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)
    ]
});

clampTime(time)number

将给定时间限制为样条线覆盖的时间段。 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.
评估给定时间的曲线。 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], 其中 , where t0 是数组中的第一个元素 is the first element in the array times and tn 是数组中的最后一个元素 is the last element in the array times.

findTimeInterval(time)number

查找索引 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], 其中 , where t0 是数组中的第一个元素 is the first element in the array times and tn 是数组中的最后一个元素 is the last element in the array times.

wrapTime(time)number

将给定时间包裹到样条线覆盖的时间段。 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.
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.