maths
Geometry, graphs and interpolation
Loading...
Searching...
No Matches
interpolation.hpp
Go to the documentation of this file.
1
8#include <vector>
9#include <array>
10
11template <int k>
13 public:
14 static inline double cubic(double factor, double start, double end) {
15 return start + factor * factor * (3.0 - 2.0 * factor) * (end - start);
16 }
17
18 static inline double linear(double factor, double start, double end) {
19 return start + factor * (end - start);
20 }
21
22 static inline std::array<double, k> linear(double factor, std::vector<std::array<double, k>> vec) {
23 std::array<std::vector<double>, k> result;
24 std::array<double, k> result_array;
25
26 for (size_t j = 0; j < k; j++) {
27 for (size_t i = 0; i < vec.size(); i++) {
28 result[j].push_back(vec[i][j]);
29 }
30 }
31
32 while (result[0].size() > 1) {
33 std::array<std::vector<double>, k> temp_result;
34
35 // Interpolate between adjacent vectors
36 for (size_t i = 0; i < k; i++) {
37 for (size_t j = 0; j < result[i].size() - 1; j++) {
38 temp_result[i].push_back(linear(factor, result[i][j], result[i][j + 1]));
39 }
40 }
41
42 result = temp_result;
43 }
44
45 for (int i = 0; i < k; i++) {
46 result_array[i] = result[i][0];
47 }
48 return result_array;
49 }
50};
Definition interpolation.hpp:12
static std::array< double, k > linear(double factor, std::vector< std::array< double, k > > vec)
Definition interpolation.hpp:22
static double linear(double factor, double start, double end)
Definition interpolation.hpp:18
static double cubic(double factor, double start, double end)
Definition interpolation.hpp:14