Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 11x 11x 11x 16x 16x 16x 16x 2x 16x 16x 11x 11x 11x 2x 11x 11x 11x 36x 36x 36x 36x 36x 36x 3x 33x 33x 33x 1x 32x 32x 32x 32x 1x 31x 31x 31x 1x 112x 55x 54x 54x 1x 8x 8x 8x 8x 8x 5x 3x 3x 1x 2x 2x 2x 1x 17x 17x 17x 17x 3x 14x 14x 1x 13x 2x 11x 11x 11x 11x 1x 7x 7x 7x 7x 7x 7x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 50x 50x 50x 50x 50x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 2x 46x 44x 46x 46x 46x 46x 46x 46x 46x | import Cartesian3 from "./Cartesian3.js";
import Cartesian4 from "./Cartesian4.js";
import Frozen from "./Frozen.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import LinearSpline from "./LinearSpline.js";
import Matrix4 from "./Matrix4.js";
import Spline from "./Spline.js";
import TridiagonalSystemSolver from "./TridiagonalSystemSolver.js";
const scratchLower = [];
const scratchDiagonal = [];
const scratchUpper = [];
const scratchRight = [];
function generateClamped(points, firstTangent, lastTangent) {
const l = scratchLower;
const u = scratchUpper;
const d = scratchDiagonal;
const r = scratchRight;
l.length = u.length = points.length - 1;
d.length = r.length = points.length;
let i;
l[0] = d[0] = 1.0;
u[0] = 0.0;
let right = r[0];
Iif (!defined(right)) {
right = r[0] = new Cartesian3();
}
Cartesian3.clone(firstTangent, right);
for (i = 1; i < l.length - 1; ++i) {
l[i] = u[i] = 1.0;
d[i] = 4.0;
right = r[i];
Iif (!defined(right)) {
right = r[i] = new Cartesian3();
}
Cartesian3.subtract(points[i + 1], points[i - 1], right);
Cartesian3.multiplyByScalar(right, 3.0, right);
}
l[i] = 0.0;
u[i] = 1.0;
d[i] = 4.0;
right = r[i];
Iif (!defined(right)) {
right = r[i] = new Cartesian3();
}
Cartesian3.subtract(points[i + 1], points[i - 1], right);
Cartesian3.multiplyByScalar(right, 3.0, right);
d[i + 1] = 1.0;
right = r[i + 1];
Iif (!defined(right)) {
right = r[i + 1] = new Cartesian3();
}
Cartesian3.clone(lastTangent, right);
return TridiagonalSystemSolver.solve(l, d, u, r);
}
function generateNatural(points) {
const l = scratchLower;
const u = scratchUpper;
const d = scratchDiagonal;
const r = scratchRight;
l.length = u.length = points.length - 1;
d.length = r.length = points.length;
let i;
l[0] = u[0] = 1.0;
d[0] = 2.0;
let right = r[0];
if (!defined(right)) {
right = r[0] = new Cartesian3();
}
Cartesian3.subtract(points[1], points[0], right);
Cartesian3.multiplyByScalar(right, 3.0, right);
for (i = 1; i < l.length; ++i) {
l[i] = u[i] = 1.0;
d[i] = 4.0;
right = r[i];
if (!defined(right)) {
right = r[i] = new Cartesian3();
}
Cartesian3.subtract(points[i + 1], points[i - 1], right);
Cartesian3.multiplyByScalar(right, 3.0, right);
}
d[i] = 2.0;
right = r[i];
if (!defined(right)) {
right = r[i] = new Cartesian3();
}
Cartesian3.subtract(points[i], points[i - 1], right);
Cartesian3.multiplyByScalar(right, 3.0, right);
return TridiagonalSystemSolver.solve(l, d, u, r);
}
/**
* 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.
*
* @alias HermiteSpline
* @constructor
*
* @param {object} options Object with the following properties:
* @param {number[]} options.times 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.
* @param {Cartesian3[]} options.points The array of control points.
* @param {Cartesian3[]} options.inTangents The array of incoming tangents at each control point.
* @param {Cartesian3[]} options.outTangents The array of outgoing tangents at each control point.
*
* @exception {DeveloperError} points.length must be greater than or equal to 2.
* @exception {DeveloperError} times.length must be equal to points.length.
* @exception {DeveloperError} inTangents and outTangents must have a length equal to points.length - 1.
* @exception {DeveloperError} 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 ConstantSpline
* @see SteppedSpline
* @see LinearSpline
* @see CatmullRomSpline
* @see QuaternionSpline
* @see MorphWeightSpline
*/
function HermiteSpline(options) {
options = options ?? Frozen.EMPTY_OBJECT;
const points = options.points;
const times = options.times;
const inTangents = options.inTangents;
const outTangents = options.outTangents;
//>>includeStart('debug', pragmas.debug);
if (
!defined(points) ||
!defined(times) ||
!defined(inTangents) ||
!defined(outTangents)
) {
throw new DeveloperError(
"times, points, inTangents, and outTangents are required.",
);
}
Iif (points.length < 2) {
throw new DeveloperError(
"points.length must be greater than or equal to 2.",
);
}
Iif (times.length !== points.length) {
throw new DeveloperError("times.length must be equal to points.length.");
}
if (
inTangents.length !== outTangents.length ||
inTangents.length !== points.length - 1
) {
throw new DeveloperError(
"inTangents and outTangents must have a length equal to points.length - 1.",
);
}
//>>includeEnd('debug');
this._times = times;
this._points = points;
this._pointType = Spline.getPointType(points[0]);
//>>includeStart('debug', pragmas.debug);
if (
this._pointType !== Spline.getPointType(inTangents[0]) ||
this._pointType !== Spline.getPointType(outTangents[0])
) {
throw new DeveloperError(
"inTangents and outTangents must be of the same type as points.",
);
}
//>>includeEnd('debug');
this._inTangents = inTangents;
this._outTangents = outTangents;
this._lastTimeIndex = 0;
}
Object.defineProperties(HermiteSpline.prototype, {
/**
* An array of times for the control points.
*
* @memberof HermiteSpline.prototype
*
* @type {number[]}
* @readonly
*/
times: {
get: function () {
return this._times;
},
},
/**
* An array of control points.
*
* @memberof HermiteSpline.prototype
*
* @type {Cartesian3[]}
* @readonly
*/
points: {
get: function () {
return this._points;
},
},
/**
* An array of incoming tangents at each control point.
*
* @memberof HermiteSpline.prototype
*
* @type {Cartesian3[]}
* @readonly
*/
inTangents: {
get: function () {
return this._inTangents;
},
},
/**
* An array of outgoing tangents at each control point.
*
* @memberof HermiteSpline.prototype
*
* @type {Cartesian3[]}
* @readonly
*/
outTangents: {
get: function () {
return this._outTangents;
},
},
});
/**
* 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>.
*
* @param {object} options Object with the following properties:
* @param {number[]} options.times The array of control point times.
* @param {Cartesian3[]} options.points The array of control points.
* @param {Cartesian3[]} options.tangents The array of tangents at the control points.
* @returns {HermiteSpline} A hermite spline.
*
* @exception {DeveloperError} points, times and tangents are required.
* @exception {DeveloperError} points.length must be greater than or equal to 2.
* @exception {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
* });
*/
HermiteSpline.createC1 = function (options) {
options = options ?? Frozen.EMPTY_OBJECT;
const times = options.times;
const points = options.points;
const tangents = options.tangents;
//>>includeStart('debug', pragmas.debug);
if (!defined(points) || !defined(times) || !defined(tangents)) {
throw new DeveloperError("points, times and tangents are required.");
}
Iif (points.length < 2) {
throw new DeveloperError(
"points.length must be greater than or equal to 2.",
);
}
if (times.length !== points.length || times.length !== tangents.length) {
throw new DeveloperError(
"times, points and tangents must have the same length.",
);
}
//>>includeEnd('debug');
const outTangents = tangents.slice(0, tangents.length - 1);
const inTangents = tangents.slice(1, tangents.length);
return new HermiteSpline({
times: times,
points: points,
inTangents: inTangents,
outTangents: outTangents,
});
};
/**
* Creates a natural cubic spline. The tangents at the control points are generated
* to create a curve in the class C<sup>2</sup>.
*
* @param {object} options Object with the following properties:
* @param {number[]} options.times The array of control point times.
* @param {Cartesian3[]} options.points The array of control points.
* @returns {HermiteSpline|LinearSpline} A hermite spline, or a linear spline if less than 3 control points were given.
*
* @exception {DeveloperError} points and times are required.
* @exception {DeveloperError} points.length must be greater than or equal to 2.
* @exception {DeveloperError} 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)
* ]
* });
*/
HermiteSpline.createNaturalCubic = function (options) {
options = options ?? Frozen.EMPTY_OBJECT;
const times = options.times;
const points = options.points;
//>>includeStart('debug', pragmas.debug);
if (!defined(points) || !defined(times)) {
throw new DeveloperError("points and times are required.");
}
Iif (points.length < 2) {
throw new DeveloperError(
"points.length must be greater than or equal to 2.",
);
}
if (times.length !== points.length) {
throw new DeveloperError("times.length must be equal to points.length.");
}
//>>includeEnd('debug');
if (points.length < 3) {
return new LinearSpline({
points: points,
times: times,
});
}
const tangents = generateNatural(points);
const outTangents = tangents.slice(0, tangents.length - 1);
const inTangents = tangents.slice(1, tangents.length);
return new HermiteSpline({
times: times,
points: points,
inTangents: inTangents,
outTangents: outTangents,
});
};
/**
* 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>.
*
* @param {object} options Object with the following properties:
* @param {number[]} options.times The array of control point times.
* @param {number[]|Cartesian3[]} options.points The array of control points.
* @param {Cartesian3} options.firstTangent The outgoing tangent of the first control point.
* @param {Cartesian3} options.lastTangent The incoming tangent of the last control point.
* @returns {HermiteSpline|LinearSpline} A hermite spline, or a linear spline if less than 3 control points were given.
*
* @exception {DeveloperError} points, times, firstTangent and lastTangent are required.
* @exception {DeveloperError} points.length must be greater than or equal to 2.
* @exception {DeveloperError} times.length must be equal to points.length.
* @exception {DeveloperError} 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)
* });
*/
HermiteSpline.createClampedCubic = function (options) {
options = options ?? Frozen.EMPTY_OBJECT;
const times = options.times;
const points = options.points;
const firstTangent = options.firstTangent;
const lastTangent = options.lastTangent;
//>>includeStart('debug', pragmas.debug);
if (
!defined(points) ||
!defined(times) ||
!defined(firstTangent) ||
!defined(lastTangent)
) {
throw new DeveloperError(
"points, times, firstTangent and lastTangent are required.",
);
}
Iif (points.length < 2) {
throw new DeveloperError(
"points.length must be greater than or equal to 2.",
);
}
Iif (times.length !== points.length) {
throw new DeveloperError("times.length must be equal to points.length.");
}
//>>includeEnd('debug');
const PointType = Spline.getPointType(points[0]);
//>>includeStart('debug', pragmas.debug);
Iif (
PointType !== Spline.getPointType(firstTangent) ||
PointType !== Spline.getPointType(lastTangent)
) {
throw new DeveloperError(
"firstTangent and lastTangent must be of the same type as points.",
);
}
//>>includeEnd('debug');
Iif (points.length < 3) {
return new LinearSpline({
points: points,
times: times,
});
}
const tangents = generateClamped(points, firstTangent, lastTangent);
const outTangents = tangents.slice(0, tangents.length - 1);
const inTangents = tangents.slice(1, tangents.length);
return new HermiteSpline({
times: times,
points: points,
inTangents: inTangents,
outTangents: outTangents,
});
};
//prettier-ignore
HermiteSpline.hermiteCoefficientMatrix = new Matrix4(
2.0, -3.0, 0.0, 1.0,
-2.0, 3.0, 0.0, 0.0,
1.0, -2.0, 1.0, 0.0,
1.0, -1.0, 0.0, 0.0
);
/**
* 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>.
* @function
*
* @param {number} time The time.
* @returns {number} The index for the element at the start of the interval.
*
* @exception {DeveloperError} time must be in the range <code>[t<sub>0</sub>, t<sub>n</sub>]</code>, where <code>t<sub>0</sub></code>
* is the first element in the array <code>times</code> and <code>t<sub>n</sub></code> is the last element
* in the array <code>times</code>.
*/
HermiteSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;
const scratchTimeVec = new Cartesian4();
const scratchTemp = new Cartesian3();
/**
* Wraps the given time to the period covered by the spline.
* @function
*
* @param {number} time The time.
* @return {number} The time, wrapped around to the updated animation.
*/
HermiteSpline.prototype.wrapTime = Spline.prototype.wrapTime;
/**
* Clamps the given time to the period covered by the spline.
* @function
*
* @param {number} time The time.
* @return {number} The time, clamped to the animation period.
*/
HermiteSpline.prototype.clampTime = Spline.prototype.clampTime;
/**
* Evaluates the curve at a given time.
*
* @param {number} time The time at which to evaluate the curve.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new instance of the point on the curve at the given time.
*
* @exception {DeveloperError} time must be in the range <code>[t<sub>0</sub>, t<sub>n</sub>]</code>, where <code>t<sub>0</sub></code>
* is the first element in the array <code>times</code> and <code>t<sub>n</sub></code> is the last element
* in the array <code>times</code>.
*/
HermiteSpline.prototype.evaluate = function (time, result) {
const points = this.points;
const times = this.times;
const inTangents = this.inTangents;
const outTangents = this.outTangents;
this._lastTimeIndex = this.findTimeInterval(time, this._lastTimeIndex);
const i = this._lastTimeIndex;
const timesDelta = times[i + 1] - times[i];
const u = (time - times[i]) / timesDelta;
const timeVec = scratchTimeVec;
timeVec.z = u;
timeVec.y = u * u;
timeVec.x = timeVec.y * u;
timeVec.w = 1.0;
// Coefficients are returned in the following order:
// start, end, out-tangent, in-tangent
const coefs = Matrix4.multiplyByVector(
HermiteSpline.hermiteCoefficientMatrix,
timeVec,
timeVec,
);
// Multiply the out-tangent and in-tangent values by the time delta.
coefs.z *= timesDelta;
coefs.w *= timesDelta;
const PointType = this._pointType;
if (PointType === Number) {
return (
points[i] * coefs.x +
points[i + 1] * coefs.y +
outTangents[i] * coefs.z +
inTangents[i] * coefs.w
);
}
if (!defined(result)) {
result = new PointType();
}
result = PointType.multiplyByScalar(points[i], coefs.x, result);
PointType.multiplyByScalar(points[i + 1], coefs.y, scratchTemp);
PointType.add(result, scratchTemp, result);
PointType.multiplyByScalar(outTangents[i], coefs.z, scratchTemp);
PointType.add(result, scratchTemp, result);
PointType.multiplyByScalar(inTangents[i], coefs.w, scratchTemp);
return PointType.add(result, scratchTemp, result);
};
export default HermiteSpline;
|