FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
math::Path Class Reference

Represents a path with coordinates and allows for various interpolation methods. More...

#include "path.h"

Public Types

enum class  InterpType { INTERP_STATIC , INTERP_LINEAR , INTERP_CUBIC }
 Types of interpolation supported by the Path class. More...
 

Public Member Functions

 Path (const InterpType type=InterpType::INTERP_STATIC) noexcept
 Constructs a Path object with a specified interpolation type.
 
 ~Path ()=default
 
 Path (const Path &)=delete
 
 Path (Path &&)=delete
 
Pathoperator= (const Path &)=delete
 
Pathoperator= (Path &&)=delete
 
void addCoord (const Coord &coord) noexcept
 Adds a coordinate to the path.
 
void finalize ()
 Finalizes the path, preparing it for interpolation.
 
InterpType getType () const noexcept
 Retrieves the current interpolation type of the path.
 
const std::vector< Coord > & getCoords () const noexcept
 Gets the list of coordinates in the path.
 
Vec3 getPosition (RealType t) const
 Retrieves the position at a given time along the path.
 
Vec3 getVelocity (RealType t) const
 Retrieves the velocity at a given time along the path.
 
void setInterp (InterpType settype) noexcept
 Changes the interpolation type.
 

Detailed Description

Represents a path with coordinates and allows for various interpolation methods.

Definition at line 29 of file path.h.

Member Enumeration Documentation

◆ InterpType

enum class math::Path::InterpType
strong

Types of interpolation supported by the Path class.

Enumerator
INTERP_STATIC 
INTERP_LINEAR 
INTERP_CUBIC 

Definition at line 35 of file path.h.

Constructor & Destructor Documentation

◆ Path() [1/3]

math::Path::Path ( const InterpType  type = InterpType::INTERP_STATIC)
explicitnoexcept

Constructs a Path object with a specified interpolation type.

Parameters
typeThe interpolation type (default is INTERP_STATIC).

Definition at line 47 of file path.h.

47: _type(type) {}

◆ ~Path()

math::Path::~Path ( )
default

◆ Path() [2/3]

math::Path::Path ( const Path )
delete

◆ Path() [3/3]

math::Path::Path ( Path &&  )
delete

Member Function Documentation

◆ addCoord()

void math::Path::addCoord ( const Coord coord)
noexcept

Adds a coordinate to the path.

Parameters
coordThe coordinate to be added.

Definition at line 26 of file path.cpp.

27 {
28 auto comp = [](const Coord& a, const Coord& b) { return a.t < b.t; };
29
30 const auto iter = std::ranges::lower_bound(_coords, coord, comp);
31 _coords.insert(iter, coord);
32 _final = false;
33 }

References math::Coord::t.

Referenced by fers_get_interpolated_motion_path(), and math::from_json().

+ Here is the caller graph for this function:

◆ finalize()

void math::Path::finalize ( )

Finalizes the path, preparing it for interpolation.

Definition at line 141 of file path.cpp.

142 {
143 if (!_final)
144 {
145 switch (_type)
146 {
149 break;
151 finalizeCubic<Coord>(_coords, _dd);
152 break;
153 }
154 _final = true;
155 }
156 }

References INTERP_CUBIC, INTERP_LINEAR, and INTERP_STATIC.

Referenced by fers_get_interpolated_motion_path(), and math::from_json().

+ Here is the caller graph for this function:

◆ getCoords()

const std::vector< Coord > & math::Path::getCoords ( ) const
noexcept

Gets the list of coordinates in the path.

Returns
A constant reference to the vector of coordinates.

Definition at line 83 of file path.h.

83{ return _coords; }

Referenced by serial::KmlGenerator::generateKml().

+ Here is the caller graph for this function:

◆ getPosition()

Vec3 math::Path::getPosition ( RealType  t) const

Retrieves the position at a given time along the path.

Parameters
tThe time parameter at which to get the position.
Returns
The interpolated position as a Vec3 object.
Exceptions
PathExceptionIf finalize() has not been called before this method.

Definition at line 35 of file path.cpp.

36 {
37 if (!_final)
38 {
39 LOG(Level::FATAL, "Finalize not called before GetPosition");
40 throw PathException("Finalize not called before GetPosition");
41 }
42
43 Coord coord{};
44 switch (_type)
45 {
47 getPositionStatic(coord, _coords);
48 break;
50 getPositionLinear(t, coord, _coords);
51 break;
53 getPositionCubic(t, coord, _coords, _dd);
54 break;
55 }
56 return coord.pos;
57 }
#define LOG(level,...)
Definition logging.h:19
void getPositionLinear(RealType t, T &coord, const std::vector< T > &coords)
Performs linear interpolation between coordinate points.
Definition path_utils.h:85
void getPositionStatic(T &coord, const std::vector< T > &coords)
Interpolates a static position from a list of coordinates.
Definition path_utils.h:66
void getPositionCubic(RealType t, T &coord, const std::vector< T > &coords, const std::vector< T > &dd)
Performs cubic spline interpolation between coordinate points.
Definition path_utils.h:128

References getPositionCubic(), getPositionLinear(), getPositionStatic(), INTERP_CUBIC, INTERP_LINEAR, INTERP_STATIC, and LOG.

Referenced by fers_get_interpolated_motion_path().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getType()

InterpType math::Path::getType ( ) const
noexcept

Retrieves the current interpolation type of the path.

Returns
The interpolation type of the path.

Definition at line 76 of file path.h.

76{ return _type; }

◆ getVelocity()

Vec3 math::Path::getVelocity ( RealType  t) const

Retrieves the velocity at a given time along the path.

Parameters
tThe time parameter at which to get the velocity.
Returns
The interpolated velocity as a Vec3 object.
Exceptions
PathExceptionIf finalize() has not been called before this method.

Definition at line 59 of file path.cpp.

60 {
61 if (!_final)
62 {
63 LOG(Level::FATAL, "Finalize not called before GetVelocity");
64 throw PathException("Finalize not called before GetVelocity");
65 }
66
67 if (_coords.empty())
68 {
69 return {0, 0, 0};
70 }
71
72 switch (_type)
73 {
75 return {0, 0, 0};
76
78 {
79 auto xrp = std::ranges::upper_bound(_coords, t, {}, &Coord::t);
80 size_t idx = std::distance(_coords.begin(), xrp);
81
82 // Clamp to valid segments
83 if (idx == 0)
84 idx = 1;
85 if (idx >= _coords.size())
86 idx = _coords.size() - 1;
87
88 if (idx < 1)
89 return {0, 0, 0}; // Should not happen if size >= 1 and clamp works
90
91 const auto& p1 = _coords[idx - 1];
92 const auto& p2 = _coords[idx];
93 const RealType dt = p2.t - p1.t;
94
95 if (dt <= EPSILON)
96 return {0, 0, 0};
97
98 return (p2.pos - p1.pos) / dt;
99 }
100
102 {
103 auto xrp = std::ranges::upper_bound(_coords, t, {}, &Coord::t);
104 size_t xri;
105 if (xrp == _coords.begin())
106 xri = 1;
107 else if (xrp == _coords.end())
108 xri = _coords.size() - 1;
109 else
110 xri = std::distance(_coords.begin(), xrp);
111
112 if (xri < 1 || xri >= _coords.size())
113 return {0, 0, 0};
114
115 size_t xli = xri - 1;
116
117 const RealType h = _coords[xri].t - _coords[xli].t;
118 if (h <= EPSILON)
119 return {0, 0, 0};
120
121 const RealType a = (_coords[xri].t - t) / h;
122 const RealType b = (t - _coords[xli].t) / h;
123
124 // Derivative coefficients
125 // da/dt = -1/h
126 // db/dt = 1/h
127 // dc/dt = -h/6 * (3a^2 - 1)
128 // dd/dt = h/6 * (3b^2 - 1)
129
130 const RealType da = -1.0 / h;
131 const RealType db = 1.0 / h;
132 const RealType dc = -h / 6.0 * (3.0 * a * a - 1.0);
133 const RealType dd_coeff = h / 6.0 * (3.0 * b * b - 1.0);
134
135 return _coords[xli].pos * da + _coords[xri].pos * db + _dd[xli].pos * dc + _dd[xri].pos * dd_coeff;
136 }
137 }
138 return {0, 0, 0};
139 }
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType EPSILON
Machine epsilon for real numbers.
Definition config.h:51
RealType t
Time.
Definition coord.h:26

References EPSILON, INTERP_CUBIC, INTERP_LINEAR, INTERP_STATIC, LOG, and math::Coord::t.

Referenced by fers_get_interpolated_motion_path().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

Path & math::Path::operator= ( const Path )
delete

◆ operator=() [2/2]

Path & math::Path::operator= ( Path &&  )
delete

◆ setInterp()

void math::Path::setInterp ( InterpType  settype)
noexcept

Changes the interpolation type.

Parameters
settypeThe new interpolation type to be used.

Definition at line 158 of file path.cpp.

159 {
160 _type = settype;
161 _final = false;
162 }

Referenced by fers_get_interpolated_motion_path(), and math::from_json().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: