Brick
Loading...
Searching...
No Matches
cubic_hermite_spline.h
1#pragma once
2
3#include <array>
4
5#include "core/math/spline/hermite_point.h"
6#include "core/math/spline/spline_base.h"
7
8/**
9 * @brief Cubic Hermite spline segment defined by endpoint positions and tangents.
10 *
11 * P(u) = c0 + c1*u + c2*u^2 + c3*u^3, where u in [0, 1].
12 */
14 public:
15 /** @brief Default constructor. */
16 CubicHermiteSpline() = default;
17
18 /**
19 * @brief Constructs cubic Hermite spline from start and end HermitePoint structures.
20 * @param start Initial endpoint with position and tangent.
21 * @param end Final endpoint with position and tangent.
22 * @param max_err Maximum allowable interpolation error in inches for the arc-length lookup table.
23 */
24 CubicHermiteSpline(const HermitePoint& start, const HermitePoint& end, double max_err = 1e-4)
25 : CubicHermiteSpline(start.point, end.point, start.tangent, end.tangent, max_err) {}
26
27 /**
28 * @brief Constructs cubic Hermite spline from explicit 2D position and tangent vectors.
29 * @param start_pos Start position vector.
30 * @param end_pos End position vector.
31 * @param start_tangent Start tangent vector.
32 * @param end_tangent End tangent vector.
33 * @param max_err Maximum allowable interpolation error in inches for the arc-length lookup table.
34 */
36 const Translation2d& start_pos, const Translation2d& end_pos,
37 const Translation2d& start_tangent, const Translation2d& end_tangent, double max_err = 1e-4
38 ) {
39 this->x_ = cubic_coeffs(
40 start_pos.x(units::in), end_pos.x(units::in), start_tangent.x(units::in),
41 end_tangent.x(units::in)
42 );
43 this->y_ = cubic_coeffs(
44 start_pos.y(units::in), end_pos.y(units::in), start_tangent.y(units::in),
45 end_tangent.y(units::in)
46 );
47 build_arc_table(max_err);
48 }
49
50 private:
51 /**
52 * @brief Computes 1D cubic Hermite polynomial coefficients [c0, c1, c2, c3].
53 */
54 static std::array<double, 4> cubic_coeffs(
55 double start_pos, double end_pos, double start_tangent, double end_tangent
56 ) {
57 return {
58 start_pos,
59 start_tangent,
60 -3.0 * start_pos + 3.0 * end_pos - 2.0 * start_tangent - end_tangent,
61 2.0 * start_pos - 2.0 * end_pos + start_tangent + end_tangent,
62 };
63 }
64};
CubicHermiteSpline(const Translation2d &start_pos, const Translation2d &end_pos, const Translation2d &start_tangent, const Translation2d &end_tangent, double max_err=1e-4)
Constructs cubic Hermite spline from explicit 2D position and tangent vectors.
Definition cubic_hermite_spline.h:35
CubicHermiteSpline(const HermitePoint &start, const HermitePoint &end, double max_err=1e-4)
Constructs cubic Hermite spline from start and end HermitePoint structures.
Definition cubic_hermite_spline.h:24
CubicHermiteSpline()=default
Default constructor.
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
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