Brick
Loading...
Searching...
No Matches
hermite_point.h
1#pragma once
2
3#include "core/math/geometry/pose2d.h"
4#include "core/math/geometry/rotation2d.h"
5#include "core/math/geometry/translation2d.h"
6#include "core/math/units.h"
7
8using namespace units::literals;
9
10/**
11 * @brief Represents a boundary point along a Hermite spline.
12 *
13 * Each point stores position (2D), first derivative (tangent/velocity),
14 * and optional second derivative (acceleration) information.
15 */
17 Translation2d point; ///< 2D position coordinates (x, y)
18 Translation2d tangent; ///< First derivative vector (dx/du, dy/du)
19 Translation2d second_derivative; ///< Second derivative vector (d^2x/du^2, d^2y/du^2)
20
21 /**
22 * @brief Default constructor initializing all vectors to zero.
23 */
24 HermitePoint() = default;
25
26 /**
27 * @brief Constructs a HermitePoint from Translation2d vectors.
28 * @param point 2D position vector.
29 * @param tangent Tangent (first derivative) vector.
30 * @param second_derivative Second derivative vector (default zero).
31 */
33 const Translation2d& point, const Translation2d& tangent,
34 const Translation2d& second_derivative = Translation2d()
35 )
37
38 /**
39 * @brief Constructs a HermitePoint from scalar position and tangent components.
40 * @param x X coordinate.
41 * @param y Y coordinate.
42 * @param vx X tangent component.
43 * @param vy Y tangent component.
44 */
45 HermitePoint(double x, double y, double vx, double vy)
46 : point(x * 1_in, y * 1_in), tangent(vx * 1_in, vy * 1_in), second_derivative(0_in, 0_in) {}
47
48 /**
49 * @brief Constructs a HermitePoint from scalar position, tangent, and second derivative
50 * components.
51 * @param x X coordinate.
52 * @param y Y coordinate.
53 * @param vx X tangent component.
54 * @param vy Y tangent component.
55 * @param ax X second derivative component.
56 * @param ay Y second derivative component.
57 */
58 HermitePoint(double x, double y, double vx, double vy, double ax, double ay)
59 : point(x * 1_in, y * 1_in),
60 tangent(vx * 1_in, vy * 1_in),
61 second_derivative(ax * 1_in, ay * 1_in) {}
62
63 /**
64 * @brief Factory method constructing HermitePoint from explicit derivative vectors.
65 * @param point 2D position vector.
66 * @param tangent Tangent vector.
67 * @param second_derivative Second derivative vector.
68 * @return Constructed HermitePoint instance.
69 */
71 const Translation2d& point, const Translation2d& tangent,
72 const Translation2d& second_derivative = Translation2d()
73 ) {
75 }
76
77 /**
78 * @brief Factory method constructing HermitePoint from heading angle and scalar speed.
79 * @param x X coordinate in inches.
80 * @param y Y coordinate in inches.
81 * @param heading Heading angle.
82 * @param speed Tangent magnitude (speed factor).
83 * @param accel_heading Second derivative direction.
84 * @param accel_mag Second derivative magnitude.
85 * @return Constructed HermitePoint instance.
86 */
88 units::Length x, units::Length y, Rotation2d heading, double speed,
89 Rotation2d accel_heading = Rotation2d(), double accel_mag = 0.0
90 ) {
91 return HermitePoint(
92 Translation2d(x, y), Translation2d(speed * 1_in, heading),
93 Translation2d(accel_mag * 1_in, accel_heading)
94 );
95 }
96
97 /**
98 * @brief Factory method constructing HermitePoint from position vector, heading angle, and
99 * speed.
100 * @param point 2D position vector.
101 * @param heading Heading angle.
102 * @param speed Tangent magnitude.
103 * @param accel_heading Second derivative direction.
104 * @param accel_mag Second derivative magnitude.
105 * @return Constructed HermitePoint instance.
106 */
108 const Translation2d& point, Rotation2d heading, double speed,
109 Rotation2d accel_heading = Rotation2d(), double accel_mag = 0.0
110 ) {
111 return HermitePoint(
112 point, Translation2d(speed * 1_in, heading), Translation2d(accel_mag * 1_in, accel_heading)
113 );
114 }
115
116 /**
117 * @brief Factory method constructing HermitePoint from Pose2d and speeds.
118 * @param pose 2D position and orientation.
119 * @param speed Tangent magnitude.
120 * @param accel_mag Second derivative magnitude.
121 * @return Constructed HermitePoint instance.
122 */
123 static HermitePoint from_pose(const Pose2d& pose, double speed, double accel_mag = 0.0) {
124 return HermitePoint(
125 pose.translation(), Translation2d(speed * 1_in, pose.rotation()),
126 Translation2d(accel_mag * 1_in, pose.rotation())
127 );
128 }
129
130 /** @return 2D position vector. */
131 Translation2d get_point() const { return point; }
132 /** @return Tangent vector. */
133 Translation2d get_tangent() const { return tangent; }
134 /** @return Second derivative vector. */
135 Translation2d get_second_derivative() const { return second_derivative; }
136};
Definition pose2d.h:21
constexpr Rotation2d rotation() const
Gets the rotation.
Definition pose2d.h:101
constexpr Translation2d translation() const
Gets the translation.
Definition pose2d.h:95
Definition rotation2d.h:16
constexpr Rotation2d()=default
Default Constructor for Rotation2d.
Definition units.h:691
HermitePoint(const Translation2d &point, const Translation2d &tangent, const Translation2d &second_derivative=Translation2d())
Constructs a HermitePoint from Translation2d vectors.
Definition hermite_point.h:32
static HermitePoint from_derivatives(const Translation2d &point, const Translation2d &tangent, const Translation2d &second_derivative=Translation2d())
Factory method constructing HermitePoint from explicit derivative vectors.
Definition hermite_point.h:70
static HermitePoint from_heading(units::Length x, units::Length y, Rotation2d heading, double speed, Rotation2d accel_heading=Rotation2d(), double accel_mag=0.0)
Factory method constructing HermitePoint from heading angle and scalar speed.
Definition hermite_point.h:87
Translation2d tangent
First derivative vector (dx/du, dy/du).
Definition hermite_point.h:18
Translation2d point
2D position coordinates (x, y)
Definition hermite_point.h:17
Translation2d second_derivative
Second derivative vector (d^2x/du^2, d^2y/du^2).
Definition hermite_point.h:19
Translation2d get_point() const
Definition hermite_point.h:131
HermitePoint()=default
Default constructor initializing all vectors to zero.
static HermitePoint from_pose(const Pose2d &pose, double speed, double accel_mag=0.0)
Factory method constructing HermitePoint from Pose2d and speeds.
Definition hermite_point.h:123
HermitePoint(double x, double y, double vx, double vy)
Constructs a HermitePoint from scalar position and tangent components.
Definition hermite_point.h:45
HermitePoint(double x, double y, double vx, double vy, double ax, double ay)
Constructs a HermitePoint from scalar position, tangent, and second derivative components.
Definition hermite_point.h:58
static HermitePoint from_heading(const Translation2d &point, Rotation2d heading, double speed, Rotation2d accel_heading=Rotation2d(), double accel_mag=0.0)
Factory method constructing HermitePoint from position vector, heading angle, and speed.
Definition hermite_point.h:107
Translation2d get_tangent() const
Definition hermite_point.h:133
Translation2d get_second_derivative() const
Definition hermite_point.h:135