62 std::vector<Translation2d> waypoints,
64 std::vector<CubicHermiteSpline> splines;
66 std::array<double, 2> x_initial = start.
x;
67 std::array<double, 2> y_initial = start.
y;
68 std::array<double, 2> x_final = end.
x;
69 std::array<double, 2> y_final = end.
y;
71 if (waypoints.size() > 1) {
72 waypoints.emplace(waypoints.begin(),
73 Translation2d{x_initial[0], y_initial[0]});
74 waypoints.emplace_back(Translation2d{x_final[0], y_final[0]});
83 std::vector<double> a;
85 std::vector<double> b(waypoints.size() - 2, 4.0);
87 std::vector<double> c;
89 std::vector<double> dx, dy;
91 std::vector<double> fx(waypoints.size() - 2, 0.0),
92 fy(waypoints.size() - 2, 0.0);
96 for (
size_t i = 0; i < waypoints.size() - 3; ++i) {
103 dx.emplace_back(3 * (waypoints[2].x() - waypoints[0].x()) - x_initial[1]);
104 dy.emplace_back(3 * (waypoints[2].y() - waypoints[0].y()) - y_initial[1]);
105 if (waypoints.size() > 4) {
106 for (
size_t i = 1; i <= waypoints.size() - 4; ++i) {
111 dx.emplace_back(3 * (waypoints[i + 2].x() - waypoints[i].x()));
112 dy.emplace_back(3 * (waypoints[i + 2].y() - waypoints[i].y()));
115 dx.emplace_back(3 * (waypoints[waypoints.size() - 1].x() -
116 waypoints[waypoints.size() - 3].x()) -
118 dy.emplace_back(3 * (waypoints[waypoints.size() - 1].y() -
119 waypoints[waypoints.size() - 3].y()) -
123 thomas_algorithm(a, b, c, dx, &fx);
124 thomas_algorithm(a, b, c, dy, &fy);
126 fx.emplace(fx.begin(), x_initial[1]);
127 fx.emplace_back(x_final[1]);
128 fy.emplace(fy.begin(), y_initial[1]);
129 fy.emplace_back(y_final[1]);
131 for (
size_t i = 0; i < fx.size() - 1; ++i) {
134 {waypoints[i + 1].x(), fx[i + 1]},
135 {waypoints[i].y(), fy[i]},
136 {waypoints[i + 1].y(), fy[i + 1]}};
138 splines.push_back(spline);
140 }
else if (waypoints.size() == 1) {
141 const double x_deriv =
142 (3 * (x_final[0] - x_initial[0]) - x_final[1] - x_initial[1]) / 4.0;
143 const double y_deriv =
144 (3 * (y_final[0] - y_initial[0]) - y_final[1] - y_initial[1]) / 4.0;
146 std::array<double, 2> mid_x_control_vector{waypoints[0].x(), x_deriv};
147 std::array<double, 2> mid_y_control_vector{waypoints[0].y(), y_deriv};
149 splines.emplace_back(x_initial, mid_x_control_vector, y_initial,
150 mid_y_control_vector);
151 splines.emplace_back(mid_x_control_vector, x_final, mid_y_control_vector,
157 splines.push_back(spline);