29 auto comp = [](
const Coord& a,
const Coord& b) {
return a.
t < b.t; };
31 const auto iter = std::ranges::lower_bound(_coords, coord, comp);
32 _coords.insert(iter, coord);
40 LOG(Level::FATAL,
"Finalize not called before GetPosition");
41 throw PathException(
"Finalize not called before GetPosition");
64 LOG(Level::FATAL,
"Finalize not called before GetVelocity");
65 throw PathException(
"Finalize not called before GetVelocity");
80 auto xrp = std::ranges::upper_bound(_coords, t, {}, &
Coord::t);
81 auto idx = std::distance(_coords.begin(), xrp);
86 if (
static_cast<std::size_t
>(idx) >= _coords.size())
87 idx =
static_cast<decltype(idx)
>(_coords.size() - 1);
89 if (idx < 1 ||
static_cast<std::size_t
>(idx) >= _coords.size())
92 const auto right_idx =
static_cast<std::size_t
>(idx);
93 const auto left_idx = right_idx - 1;
95 const auto& p1 = _coords[left_idx];
96 const auto& p2 = _coords[right_idx];
102 return (p2.pos - p1.pos) / dt;
107 auto xrp = std::ranges::upper_bound(_coords, t, {}, &
Coord::t);
109 if (xrp == _coords.begin())
111 else if (xrp == _coords.end())
112 xri =
static_cast<std::ptrdiff_t
>(_coords.size() - 1);
114 xri = std::distance(_coords.begin(), xrp);
116 if (xri < 1 ||
static_cast<std::size_t
>(xri) >= _coords.size())
119 const auto right_idx =
static_cast<std::size_t
>(xri);
120 const auto left_idx = right_idx - 1;
122 const RealType h = _coords[right_idx].t - _coords[left_idx].t;
126 const RealType a = (_coords[right_idx].t - t) / h;
127 const RealType b = (t - _coords[left_idx].t) / h;
137 const RealType dc = -h / 6.0 * (3.0 * a * a - 1.0);
138 const RealType dd_coeff = h / 6.0 * (3.0 * b * b - 1.0);
140 return _coords[left_idx].pos * da + _coords[right_idx].pos * db + _dd[left_idx].pos * dc +
141 _dd[right_idx].pos * dd_coeff;
157 finalizeCubic<Coord>(_coords, _dd);
Exception class for handling path-related errors.
Vec3 getPosition(RealType t) const
Retrieves the position at a given time along the path.
void setInterp(InterpType settype) noexcept
Changes the interpolation type.
InterpType
Types of interpolation supported by the Path class.
Vec3 getVelocity(RealType t) const
Retrieves the velocity at a given time along the path.
void addCoord(const Coord &coord) noexcept
Adds a coordinate to the path.
void finalize()
Finalizes the path, preparing it for interpolation.
A class representing a vector in rectangular coordinates.
double RealType
Type for real numbers.
constexpr RealType EPSILON
Machine epsilon for real numbers.
Coordinate and rotation structure operations.
Classes and operations for 3D geometry.
Header file for the logging system.
Provides the definition and functionality of the Path class for handling coordinate-based paths with ...
Utility functions for path interpolation and exception handling.
void getPositionLinear(RealType t, T &coord, const std::vector< T > &coords)
Performs linear interpolation between coordinate points.
void getPositionStatic(T &coord, const std::vector< T > &coords)
Interpolates a static position from a list of coordinates.
void getPositionCubic(RealType t, T &coord, const std::vector< T > &coords, const std::vector< T > &dd)
Performs cubic spline interpolation between coordinate points.
Represents a position in 3D space with an associated time.