15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
import { HermitePolynomialApproximation } from "../../Source/Cesium.js";
 
describe("Core/HermitePolynomialApproximation", function () {
  //The results of these specs were validated against STK Components
  //an aerospace SDK available from Analytical Graphics. www.agi.com/components/
 
  var xTable = [0, 60, 120, 180, 240, 300, 360, 420];
  var yTable = [
    13378137.0,
    0,
    13374128.3576279,
    0,
    13362104.8328212,
    0,
    13342073.6310691,
    0,
    13314046.7567223,
    0,
    13278041.005799,
    0,
    13234077.9559193,
    0,
    13182183.953374,
    0,
  ];
  var dyTable = [
    0.0,
    0,
    -133.614738921601,
    0,
    -267.149404854867,
    0,
    -400.523972797808,
    0,
    -533.658513692378,
    0,
    -666.473242324565,
    0,
    -798.888565138278,
    0,
    -930.82512793439,
    0,
  ];
 
  var yTableCombined = new Array(yTable.length * 2);
 
  for (var i = 0; i < yTable.length / 2; ++i) {
    yTableCombined[i * 4 + 0] = yTable[i * 2 + 0];
    yTableCombined[i * 4 + 1] = yTable[i * 2 + 1];
    yTableCombined[i * 4 + 2] = dyTable[i * 2 + 0];
    yTableCombined[i * 4 + 3] = dyTable[i * 2 + 1];
  }
 
  var x = 100.0;
 
  it("interpolating produces correct results.", function () {
    // Since we want a zero order calculation we need to switch to a yStride of 4.
    var result = HermitePolynomialApproximation.interpolateOrderZero(
      x,
      xTable,
      yTableCombined,
      4
    );
    var expectedResult = 13367002.870928625;
    //The accuracy is lower because we are no longer using derivative info
    expect(result[0]).toEqualEpsilon(expectedResult, 1e-6);
  });
 
  it("interpolating produces correct results with a result parameter.", function () {
    // Since we want a zero order calculation we need to switch to a yStride of 4.
    var result = new Array(4);
    var returnedResult = HermitePolynomialApproximation.interpolateOrderZero(
      x,
      xTable,
      yTableCombined,
      4,
      result
    );
    var expectedResult = 13367002.870928625;
    expect(result).toBe(returnedResult);
    //The accuracy is lower because we are no longer using derivative info
    expect(result[0]).toEqualEpsilon(expectedResult, 1e-6);
  });
 
  it("getRequiredDataPoints should be 1 more than degree, except for 0, which requires 2", function () {
    expect(HermitePolynomialApproximation.getRequiredDataPoints(0)).toEqual(2);
    expect(HermitePolynomialApproximation.getRequiredDataPoints(1)).toEqual(2);
    expect(HermitePolynomialApproximation.getRequiredDataPoints(2)).toEqual(3);
    expect(HermitePolynomialApproximation.getRequiredDataPoints(3)).toEqual(4);
    expect(HermitePolynomialApproximation.getRequiredDataPoints(3, 1)).toEqual(
      2
    );
    expect(HermitePolynomialApproximation.getRequiredDataPoints(5, 1)).toEqual(
      3
    );
    expect(HermitePolynomialApproximation.getRequiredDataPoints(7, 1)).toEqual(
      4
    );
  });
 
  it("higher order interpolation produces correct results.", function () {
    var result = HermitePolynomialApproximation.interpolate(
      x,
      xTable,
      yTableCombined,
      2,
      1,
      1
    );
    var expectedResult = [13367002.870928625, 0.0, -222.65168787012135, 0.0];
    expect(result).toEqualEpsilon(expectedResult, 1e-8);
  });
});