-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
84 lines (70 loc) · 2.87 KB
/
main.cpp
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
#include <fstream>
#include <iomanip>
#include <iostream>
#include "piecewise_spline.h"
int main()
{
std::vector<double> breaks = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
std::vector<Eigen::VectorXd> knots = {
Eigen::Vector3d(5.22, 9.60, -8.85),
Eigen::Vector3d(8.92, -1.87, 4.30),
Eigen::Vector3d(6.40, -4.81, 5.55),
Eigen::Vector3d(8.76, -9.99, 5.52),
Eigen::Vector3d(5.49, -9.63, -3.81),
Eigen::Vector3d(-1.04, 2.45, -3.17),
Eigen::Vector3d(-4.57, -2.53, 8.27)};
// 零阶保持器测试
PiecewiseSpline q0 = PiecewiseSpline::ZeroOrderHold(breaks, knots);
// 线性插值测试
PiecewiseSpline q1 = PiecewiseSpline::LinearSpline(breaks, knots);
// 三次样条差值测试 Natural Condition
PiecewiseSpline q3_natural = PiecewiseSpline::CubicSpline(breaks, knots);
// 三次样条差值测试 NotAKnot Condition
PiecewiseSpline q3_not_a_knot = PiecewiseSpline::CubicSpline(breaks, knots, false);
// 三次样条差值测试 Clamp Condition
Eigen::VectorXd clamped_start = Eigen::Vector3d(0, 0, 0);
Eigen::VectorXd clamped_end = Eigen::Vector3d(0, 0, 0);
PiecewiseSpline q3_clamp = PiecewiseSpline::CubicSpline(breaks, knots, clamped_start, clamped_end);
// begin test
int num_samps = 1000;
double start = breaks[0], end = breaks[breaks.size() - 1];
std::string filename0 = "../log/knots.csv";
std::string filename1 = "../log/element0.csv";
std::string filename2 = "../log/element1.csv";
std::string filename3 = "../log/element2.csv";
std::ofstream file0(filename0), file1(filename1), file2(filename2), file3(filename3);
// load knots
for (int i = 0; i < breaks.size(); ++i)
{
file0 << breaks[i] << "," << knots[i](0) << "," << knots[i](1) << "," << knots[i](2) << std::endl;
}
// load spline data
for (int i = 0; i < num_samps; ++i)
{
double step = (end - start) / (num_samps - 1);
double samp = start + i * step;
file1 << samp << ","
<< q0.value(samp)(0) << ","
<< q1.value(samp)(0) << ","
<< q3_natural.value(samp)(0) << ","
<< q3_not_a_knot.value(samp)(0) << ","
<< q3_clamp.value(samp)(0) << std::endl;
file2 << samp << ","
<< q0.value(samp)(1) << ","
<< q1.value(samp)(1) << ","
<< q3_natural.value(samp)(1) << ","
<< q3_not_a_knot.value(samp)(1) << ","
<< q3_clamp.value(samp)(1) << std::endl;
file3 << samp << ","
<< q0.value(samp)(2) << ","
<< q1.value(samp)(2) << ","
<< q3_natural.value(samp)(2) << ","
<< q3_not_a_knot.value(samp)(2) << ","
<< q3_clamp.value(samp)(2) << std::endl;
}
file0.close();
file1.close();
file2.close();
file3.close();
return 0;
}