31 const Eigen::VectorXd &y) {
32 if (x.size() != y.size()) {
33 throw std::invalid_argument(
34 "error in AkimaSpline::Interpolate : sizes of vectors x and y do not "
40 throw std::invalid_argument(
41 "error in AkimaSpline::Interpolate : vectors x and y have to contain "
45 const Index N = x.size();
51 p0 = Eigen::VectorXd::Zero(N);
52 p1 = Eigen::VectorXd::Zero(N);
53 p2 = Eigen::VectorXd::Zero(N);
54 p3 = Eigen::VectorXd::Zero(N);
55 t = Eigen::VectorXd::Zero(N);
57 double m1, m2, m3, m4;
59 double temp, g0, g1, g2, x1, x2, y1, y2, x4, x5, y4, y5, m5;
70 temp = (x(1) - x(0)) / (x(2) - x(0));
73 g1 = ((y(1) - y(0)) - temp * (y(2) - y(0))) /
74 ((x(1) - x(0)) - temp * (x(2) - x(0)));
75 g2 = ((y(2) - y(0)) - g1 * (x(2) - x(0))) /
76 ((x(2) - x(0)) * (x(2) - x(0)));
77 x1 = x(0) - (x(2) - x(0));
78 x2 = x(1) - (x(2) - x(0));
79 y1 = g0 + g1 * (x1 - x(0)) + g2 * (x1 - x(0)) * (x1 - x(0));
80 y2 = g0 + g1 * (x2 - x(0)) + g2 * (x2 - x(0)) * (x2 - x(0));
81 m1 = (y2 - y1) / (x2 - x1);
82 m2 = (y(0) - y2) / (x(0) - x2);
83 m3 = (y(1) - y(0)) / (x(1) - x(0));
84 m4 = (y(2) - y(1)) / (x(2) - x(1));
86 m5 = (y(3) - y(2)) / (x(3) - x(2));
90 temp = (x(N - 2) - x(N - 1)) / (x(N - 3) - x(N - 1));
93 g1 = ((y(N - 2) - y(N - 1)) - temp * (y(N - 3) - y(N - 1))) /
94 ((x(N - 2) - x(N - 1)) - temp * (x(N - 3) - x(N - 1)));
95 g2 = ((y(N - 3) - y(N - 1)) - g1 * (x(N - 3) - x(N - 1))) /
96 ((x(N - 3) - x(N - 1)) * (x(N - 3) - x(N - 1)));
97 x4 = x(N - 2) + (x(N - 1) - x(N - 3));
98 x5 = x(N - 1) + (x(N - 1) - x(N - 3));
99 y4 = g0 + g1 * (x4 - x(N - 1)) + g2 * (x4 - x(N - 1)) * (x4 - x(N - 1));
100 y5 = g0 + g1 * (x5 - x(N - 1)) + g2 * (x5 - x(N - 1)) * (x5 - x(N - 1));
101 m1 = (y(N - 3) - y(N - 4)) / (x(N - 3) - x(N - 4));
102 m2 = (y(N - 2) - y(N - 3)) / (x(N - 2) - x(N - 3));
103 m3 = (y(N - 1) - y(N - 2)) / (x(N - 1) - x(N - 2));
104 m4 = (y4 - y(N - 1)) / (x4 - x(N - 1));
105 m5 = (y5 - y4) / (x5 - x4);
111 m1 = (y(N - 1) - y(N - 2)) / (x(N - 1) - x(N - 2));
112 m2 = (y(0) - y(N - 1)) / (x(0) - x(N - 1));
113 m3 = (y(1) - y(0)) / (x(1) - x(0));
114 m4 = (y(2) - y(1)) / (x(2) - x(1));
115 m5 = (y(3) - y(2)) / (x(3) - x(2));
119 m1 = (y(N - 3) - y(N - 4)) / (x(N - 3) - x(N - 4));
120 m2 = (y(N - 2) - y(N - 3)) / (x(N - 2) - x(N - 3));
121 m3 = (y(N - 1) - y(N - 2)) / (x(N - 1) - x(N - 2));
122 m4 = (y(0) - y(N - 1)) / (x(0) - x(N - 1));
123 m5 = (y(1) - y(0)) / (x(1) - x(0));
128 throw std::runtime_error(
129 "erro in AkimaSpline::Interpolate: case splineDerivativeZero not "
135 for (
Index i = 2; i < N - 2; i++) {
136 m1 = (y(i - 1) - y(i - 2)) / (x(i - 1) - x(i - 2));
137 m2 = (y(i) - y(i - 1)) / (x(i) - x(i - 1));
138 m3 = (y(i + 1) - y(i)) / (x(i + 1) - x(i));
139 m4 = (y(i + 2) - y(i + 1)) / (x(i + 2) - x(i + 1));
146 for (
Index i = 0; i < N - 1; i++) {
150 (3.0 * (y(i + 1) - y(i)) / (x(i + 1) - x(i)) - 2.0 *
t(i) -
t(i + 1)) /
152 p3(i) = (
t(i) +
t(i + 1) - 2.0 * (y(i + 1) - y(i)) / (x(i + 1) - x(i))) /
153 ((x(i + 1) - x(i)) * (x(i + 1) - x(i)));