Brick
Loading...
Searching...
No Matches
quintic_hermite_spline.h
1#pragma once
2
3#include <array>
4
5#include "core/math/spline/cubic_hermite_spline.h"
6
7/**
8 * @brief Quintic Hermite spline segment defined by endpoint positions, tangents, and second
9 * derivatives.
10 *
11 * P(u) = c0 + c1*u + c2*u^2 + c3*u^3 + c4*u^4 + c5*u^5, where u in [0, 1].
12 */
14 public:
15 /** @brief Default constructor. */
17
18 /**
19 * @brief Constructs quintic Hermite spline from start and end HermitePoint structures.
20 * @param start Initial endpoint with position, tangent, and second derivative.
21 * @param end Final endpoint with position, tangent, and second derivative.
22 * @param max_err Maximum allowable interpolation error in inches for the arc-length lookup table.
23 */
24 QuinticHermiteSpline(const HermitePoint& start, const HermitePoint& end, double max_err = 1e-4)
26 start.point, end.point, start.tangent, end.tangent, start.second_derivative,
27 end.second_derivative, max_err
28 ) {}
29
30 /**
31 * @brief Constructs quintic Hermite spline from explicit 2D position, tangent, and acceleration
32 * vectors.
33 * @param start_pos Start position vector.
34 * @param end_pos End position vector.
35 * @param start_tangent Start tangent vector.
36 * @param end_tangent End tangent vector.
37 * @param start_accel Start second derivative vector.
38 * @param end_accel End second derivative vector.
39 * @param max_err Maximum allowable interpolation error in inches for the arc-length lookup table.
40 */
42 const Translation2d& start_pos, const Translation2d& end_pos,
43 const Translation2d& start_tangent, const Translation2d& end_tangent,
44 const Translation2d& start_accel, const Translation2d& end_accel, double max_err = 1e-4
45 ) {
46 this->x_ = quintic_coeffs(
47 start_pos.x(units::in), end_pos.x(units::in), start_tangent.x(units::in),
48 end_tangent.x(units::in), start_accel.x(units::in), end_accel.x(units::in)
49 );
50 this->y_ = quintic_coeffs(
51 start_pos.y(units::in), end_pos.y(units::in), start_tangent.y(units::in),
52 end_tangent.y(units::in), start_accel.y(units::in), end_accel.y(units::in)
53 );
54 build_arc_table(max_err);
55 }
56
57 private:
58 /**
59 * @brief Computes 1D quintic Hermite polynomial coefficients [c0, c1, c2, c3, c4, c5].
60 */
61 static std::array<double, 6> quintic_coeffs(
62 double start_pos, double end_pos, double start_tangent, double end_tangent,
63 double start_accel, double end_accel
64 ) {
65 return {
66 start_pos,
67 start_tangent,
68 start_accel / 2.0,
69 (-20.0 * start_pos + 20.0 * end_pos - 12.0 * start_tangent - 8.0 * end_tangent -
70 3.0 * start_accel + end_accel) /
71 2.0,
72 (30.0 * start_pos - 30.0 * end_pos + 16.0 * start_tangent + 14.0 * end_tangent +
73 3.0 * start_accel - 2.0 * end_accel) /
74 2.0,
75 (-12.0 * start_pos + 12.0 * end_pos - 6.0 * start_tangent - 6.0 * end_tangent -
76 start_accel + end_accel) /
77 2.0,
78 };
79 }
80};
CRTP base class for Hermite splines of specific polynomial order.
Definition spline_base.h:346
constexpr Q x() const
Gets the x component.
Definition translation2d.h:64
constexpr Q y() const
Gets the y component.
Definition translation2d.h:73
QuinticHermiteSpline()=default
Default constructor.
QuinticHermiteSpline(const Translation2d &start_pos, const Translation2d &end_pos, const Translation2d &start_tangent, const Translation2d &end_tangent, const Translation2d &start_accel, const Translation2d &end_accel, double max_err=1e-4)
Constructs quintic Hermite spline from explicit 2D position, tangent, and acceleration vectors.
Definition quintic_hermite_spline.h:41
QuinticHermiteSpline(const HermitePoint &start, const HermitePoint &end, double max_err=1e-4)
Constructs quintic Hermite spline from start and end HermitePoint structures.
Definition quintic_hermite_spline.h:24
void build_arc_table(double max_err=1e-4)
Builds pre-computed parameter u and arc-length lookup tables using adaptive refinement.
Definition spline_base.h:281
Represents a boundary point along a Hermite spline.
Definition hermite_point.h:16