FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
math Namespace Reference

Classes

class  Coord
 Represents a position in 3D space with an associated time. More...
 
class  Matrix3
 A class representing a 3x3 matrix. More...
 
class  Path
 Represents a path with coordinates and allows for various interpolation methods. More...
 
class  PathException
 Exception class for handling path-related errors. More...
 
class  RotationCoord
 Represents a rotation in terms of azimuth, elevation, and time. More...
 
class  RotationPath
 Manages rotational paths with different interpolation techniques. More...
 
class  SVec3
 A class representing a vector in spherical coordinates. More...
 
class  Vec3
 A class representing a vector in rectangular coordinates. More...
 

Functions

Coord operator* (const Coord &a, const Coord &b) noexcept
 Multiplies two Coord objects' positions and copies the time.
 
Coord operator+ (const Coord &a, const Coord &b) noexcept
 Adds two Coord objects' positions and copies the time.
 
Coord operator- (const Coord &a, const Coord &b) noexcept
 Subtracts two Coord objects' positions and copies the time.
 
Coord operator/ (const Coord &a, const Coord &b) noexcept
 Divides two Coord objects' positions and copies the time.
 
Coord operator+ (const Coord &a, const RealType b) noexcept
 Adds a scalar to a Coord's position while copying the time.
 
Coord operator* (const Coord &a, const RealType b) noexcept
 Multiplies a Coord's position by a scalar while copying the time.
 
Coord operator/ (const RealType a, const Coord &b) noexcept
 Divides a scalar by a Coord's position and copies the time.
 
Coord operator/ (const Coord &b, const RealType a) noexcept
 Divides a Coord's position by a scalar while copying the time.
 
RotationCoord operator* (const RotationCoord &a, const RotationCoord &b) noexcept
 Multiplies two RotationCoord objects' components and copies the time.
 
RotationCoord operator+ (const RotationCoord &a, const RotationCoord &b) noexcept
 Adds two RotationCoord objects' components and copies the time.
 
RotationCoord operator- (const RotationCoord &a, const RotationCoord &b) noexcept
 Subtracts two RotationCoord objects' components and copies the time.
 
RotationCoord operator/ (const RotationCoord &a, const RotationCoord &b) noexcept
 Divides two RotationCoord objects' components and copies the time.
 
RotationCoord operator+ (const RotationCoord &a, const RealType b) noexcept
 Adds a scalar to a RotationCoord's components while copying the time.
 
RotationCoord operator* (const RotationCoord &a, const RealType b) noexcept
 Multiplies a RotationCoord's components by a scalar while copying the time.
 
RotationCoord operator/ (const RealType a, const RotationCoord &b) noexcept
 Divides a scalar by a RotationCoord's components and copies the time.
 
RotationCoord operator/ (const RotationCoord &b, const RealType a) noexcept
 Divides a RotationCoord's components by a scalar while copying the time.
 
SVec3 operator+ (const SVec3 &a, const SVec3 &b) noexcept
 Adds two SVec3 vectors.
 
SVec3 operator- (const SVec3 &a, const SVec3 &b) noexcept
 Subtracts two SVec3 vectors.
 
RealType dotProduct (const Vec3 &a, const Vec3 &b) noexcept
 Computes the dot product of two Vec3 vectors.
 
Vec3 operator* (const Vec3 &a, const Vec3 &b) noexcept
 Multiplies two Vec3 vectors component-wise.
 
Vec3 operator+ (const Vec3 &a, const Vec3 &b) noexcept
 Adds two Vec3 vectors component-wise.
 
Vec3 operator- (const Vec3 &a, const Vec3 &b) noexcept
 Subtracts two Vec3 vectors component-wise.
 
Vec3 operator/ (const Vec3 &a, const Vec3 &b)
 Divides two Vec3 vectors component-wise.
 
Vec3 operator* (const Vec3 &a, const RealType b) noexcept
 Multiplies a Vec3 vector by a scalar value.
 
Vec3 operator/ (const Vec3 &a, const RealType b) noexcept
 Divides a Vec3 vector by a scalar value.
 
Vec3 operator/ (const RealType a, const Vec3 &b) noexcept
 Divides a scalar value by a Vec3 vector.
 
void to_json (nlohmann::json &j, const Vec3 &v)
 
void from_json (const nlohmann::json &j, Vec3 &v)
 
void to_json (nlohmann::json &j, const Coord &c)
 
void from_json (const nlohmann::json &j, Coord &c)
 
void to_json (nlohmann::json &j, const RotationCoord &rc)
 
void from_json (const nlohmann::json &j, RotationCoord &rc)
 
 NLOHMANN_JSON_SERIALIZE_ENUM (Path::InterpType, {{Path::InterpType::INTERP_STATIC, "static"}, {Path::InterpType::INTERP_LINEAR, "linear"}, {Path::InterpType::INTERP_CUBIC, "cubic"}}) void to_json(nlohmann
 
void from_json (const nlohmann::json &j, Path &p)
 
 NLOHMANN_JSON_SERIALIZE_ENUM (RotationPath::InterpType, {{RotationPath::InterpType::INTERP_STATIC, "static"}, {RotationPath::InterpType::INTERP_CONSTANT, "constant"}, {RotationPath::InterpType::INTERP_LINEAR, "linear"}, {RotationPath::InterpType::INTERP_CUBIC, "cubic"}}) void to_json(nlohmann
 
void from_json (const nlohmann::json &j, RotationPath &p)
 

Function Documentation

◆ dotProduct()

RealType math::dotProduct ( const Vec3 a,
const Vec3 b 
)
noexcept

Computes the dot product of two Vec3 vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The dot product of the vectors.

Definition at line 207 of file geometry_ops.h.

207{ return a.x * b.x + a.y * b.y + a.z * b.z; }
RealType x
The x component of the vector.
RealType z
The z component of the vector.
RealType y
The y component of the vector.

◆ from_json() [1/5]

void math::from_json ( const nlohmann::json &  j,
Coord c 
)

Definition at line 55 of file json_serializer.cpp.

56 {
57 j.at("time").get_to(c.t);
58 j.at("x").get_to(c.pos.x);
59 j.at("y").get_to(c.pos.y);
60 j.at("altitude").get_to(c.pos.z);
61 }

◆ from_json() [2/5]

void math::from_json ( const nlohmann::json &  j,
Path p 
)

Definition at line 97 of file json_serializer.cpp.

98 {
99 p.setInterp(j.at("interpolation").get<Path::InterpType>());
100 for (const auto waypoints = j.at("positionwaypoints").get<std::vector<Coord>>(); const auto& wp : waypoints)
101 {
102 p.addCoord(wp);
103 }
104 p.finalize();
105 }
void setInterp(InterpType settype) noexcept
Changes the interpolation type.
Definition path.cpp:158
InterpType
Types of interpolation supported by the Path class.
Definition path.h:36
void addCoord(const Coord &coord) noexcept
Adds a coordinate to the path.
Definition path.cpp:26
void finalize()
Finalizes the path, preparing it for interpolation.
Definition path.cpp:141

References math::Path::addCoord(), math::Path::finalize(), and math::Path::setInterp().

+ Here is the call graph for this function:

◆ from_json() [3/5]

void math::from_json ( const nlohmann::json &  j,
RotationCoord rc 
)

Definition at line 74 of file json_serializer.cpp.

75 {
76 j.at("time").get_to(rc.t);
77 const RealType az_deg = j.at("azimuth").get<RealType>();
78 const RealType el_deg = j.at("elevation").get<RealType>();
79
80 // Convert from compass degrees (from JSON/UI) back to the internal engine's
81 // mathematical angle representation (radians, CCW from East). This keeps
82 // all internal physics calculations consistent.
83 rc.azimuth = (90.0 - az_deg) * (PI / 180.0);
84 rc.elevation = el_deg * (PI / 180.0);
85 }
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43
RealType t
Time.
Definition coord.h:75
RealType elevation
Elevation angle.
Definition coord.h:74
RealType azimuth
Azimuth angle.
Definition coord.h:73

References math::RotationCoord::azimuth, math::RotationCoord::elevation, PI, and math::RotationCoord::t.

◆ from_json() [4/5]

void math::from_json ( const nlohmann::json &  j,
RotationPath p 
)

Definition at line 140 of file json_serializer.cpp.

141 {
142 p.setInterp(j.at("interpolation").get<RotationPath::InterpType>());
143 for (const auto waypoints = j.at("rotationwaypoints").get<std::vector<RotationCoord>>();
144 const auto& wp : waypoints)
145 {
146 p.addCoord(wp);
147 }
148 p.finalize();
149 }
void finalize()
Finalizes the rotation path for interpolation.
void setInterp(InterpType setinterp) noexcept
Sets the interpolation type for the path.
InterpType
Enumeration for types of interpolation.
void addCoord(const RotationCoord &coord) noexcept
Adds a rotation coordinate to the path.

References math::RotationPath::addCoord(), math::RotationPath::finalize(), and math::RotationPath::setInterp().

+ Here is the call graph for this function:

◆ from_json() [5/5]

void math::from_json ( const nlohmann::json &  j,
Vec3 v 
)

Definition at line 43 of file json_serializer.cpp.

44 {
45 j.at("x").get_to(v.x);
46 j.at("y").get_to(v.y);
47 j.at("z").get_to(v.z);
48 }

References math::Vec3::x, math::Vec3::y, and math::Vec3::z.

◆ NLOHMANN_JSON_SERIALIZE_ENUM() [1/2]

math::NLOHMANN_JSON_SERIALIZE_ENUM ( Path::InterpType  ,
{{Path::InterpType::INTERP_STATIC, "static"}, {Path::InterpType::INTERP_LINEAR, "linear"}, {Path::InterpType::INTERP_CUBIC, "cubic"}}   
)

Definition at line 87 of file json_serializer.cpp.

88 {{Path::InterpType::INTERP_STATIC, "static"},
89 {Path::InterpType::INTERP_LINEAR, "linear"},
90 {Path::InterpType::INTERP_CUBIC, "cubic"}})
91
92 void to_json(nlohmann::json& j, const Path& p)
93 {
94 j = {{"interpolation", p.getType()}, {"positionwaypoints", p.getCoords()}};
95 }
void to_json(nlohmann::json &j, const Vec3 &v)

References math::Path::INTERP_CUBIC, math::Path::INTERP_LINEAR, and math::Path::INTERP_STATIC.

◆ NLOHMANN_JSON_SERIALIZE_ENUM() [2/2]

Definition at line 107 of file json_serializer.cpp.

108 {{RotationPath::InterpType::INTERP_STATIC, "static"},
109 {RotationPath::InterpType::INTERP_CONSTANT,
110 "constant"}, // Not used in xml_parser or UI yet, but for completeness
111 {RotationPath::InterpType::INTERP_LINEAR, "linear"},
112 {RotationPath::InterpType::INTERP_CUBIC, "cubic"}})
113
114 void to_json(nlohmann::json& j, const RotationPath& p)
115 {
116 j["interpolation"] = p.getType();
117 // This logic exists to map the two different rotation definitions from the
118 // XML schema (<fixedrotation> and <rotationpath>) into a unified JSON
119 // structure that the frontend can more easily handle.
120 if (p.getType() == RotationPath::InterpType::INTERP_CONSTANT)
121 {
122 // A constant-rate rotation path corresponds to the <fixedrotation> XML element.
123 // The start and rate values are converted to compass degrees per second.
124 // No normalization is applied to preserve negative start angles.
125 const RealType start_az_deg = 90.0 - p.getStart().azimuth * 180.0 / PI;
126 const RealType start_el_deg = p.getStart().elevation * 180.0 / PI;
127 const RealType rate_az_deg_s = -p.getRate().azimuth * 180.0 / PI; // Invert for CW rate
128 const RealType rate_el_deg_s = p.getRate().elevation * 180.0 / PI;
129 j["startazimuth"] = start_az_deg;
130 j["startelevation"] = start_el_deg;
131 j["azimuthrate"] = rate_az_deg_s;
132 j["elevationrate"] = rate_el_deg_s;
133 }
134 else
135 {
136 j["rotationwaypoints"] = p.getCoords();
137 }
138 }

References math::RotationPath::INTERP_CONSTANT, math::RotationPath::INTERP_CUBIC, math::RotationPath::INTERP_LINEAR, and math::RotationPath::INTERP_STATIC.

◆ operator*() [1/6]

Coord math::operator* ( const Coord a,
const Coord b 
)
noexcept

Multiplies two Coord objects' positions and copies the time.

Definition at line 51 of file coord.h.

51{ return {a.pos * b.pos, a.t}; }
RealType t
Time.
Definition coord.h:26
Vec3 pos
3D position
Definition coord.h:25

References math::Coord::pos.

◆ operator*() [2/6]

Coord math::operator* ( const Coord a,
const RealType  b 
)
noexcept

Multiplies a Coord's position by a scalar while copying the time.

Definition at line 61 of file coord.h.

61{ return {a.pos * b, a.t}; }

References math::Coord::pos.

◆ operator*() [3/6]

RotationCoord math::operator* ( const RotationCoord a,
const RealType  b 
)
noexcept

Multiplies a RotationCoord's components by a scalar while copying the time.

Definition at line 148 of file coord.h.

149 {
150 return {a.azimuth * b, a.elevation * b, a.t};
151 }

References math::Coord::t.

◆ operator*() [4/6]

RotationCoord math::operator* ( const RotationCoord a,
const RotationCoord b 
)
noexcept

Multiplies two RotationCoord objects' components and copies the time.

Definition at line 118 of file coord.h.

119 {
120 return {a.azimuth * b.azimuth, a.elevation * b.elevation, a.t};
121 }

References math::Coord::t.

◆ operator*() [5/6]

Vec3 math::operator* ( const Vec3 a,
const RealType  b 
)
noexcept

Multiplies a Vec3 vector by a scalar value.

Definition at line 229 of file geometry_ops.h.

229{ return {a.x * b, a.y * b, a.z * b}; }

◆ operator*() [6/6]

Vec3 math::operator* ( const Vec3 a,
const Vec3 b 
)
noexcept

Multiplies two Vec3 vectors component-wise.

Definition at line 217 of file geometry_ops.h.

217{ return {a.x * b.x, a.y * b.y, a.z * b.z}; }

◆ operator+() [1/6]

Coord math::operator+ ( const Coord a,
const Coord b 
)
noexcept

Adds two Coord objects' positions and copies the time.

Definition at line 53 of file coord.h.

53{ return {a.pos + b.pos, a.t}; }

References math::Coord::pos.

◆ operator+() [2/6]

Coord math::operator+ ( const Coord a,
const RealType  b 
)
noexcept

Adds a scalar to a Coord's position while copying the time.

Definition at line 59 of file coord.h.

59{ return {a.pos + b, a.t}; }

References math::Coord::pos.

◆ operator+() [3/6]

RotationCoord math::operator+ ( const RotationCoord a,
const RealType  b 
)
noexcept

Adds a scalar to a RotationCoord's components while copying the time.

Definition at line 142 of file coord.h.

143 {
144 return {a.azimuth + b, a.elevation + b, a.t};
145 }

References math::Coord::t.

◆ operator+() [4/6]

RotationCoord math::operator+ ( const RotationCoord a,
const RotationCoord b 
)
noexcept

Adds two RotationCoord objects' components and copies the time.

Definition at line 124 of file coord.h.

125 {
126 return {a.azimuth + b.azimuth, a.elevation + b.elevation, a.t};
127 }

References math::Coord::t.

◆ operator+() [5/6]

SVec3 math::operator+ ( const SVec3 a,
const SVec3 b 
)
noexcept

Adds two SVec3 vectors.

Definition at line 91 of file geometry_ops.cpp.

92 {
93 RealType new_azimuth = fmod(a.azimuth + b.azimuth, 2 * PI);
94 if (new_azimuth < 0)
95 {
96 new_azimuth += 2 * PI;
97 }
98 RealType new_elevation = fmod(a.elevation + b.elevation, PI);
99 return {a.length + b.length, new_azimuth, new_elevation};
100 }
RealType elevation
The elevation angle of the vector.
RealType azimuth
The azimuth angle of the vector.
RealType length
The length of the vector.

References PI.

◆ operator+() [6/6]

Vec3 math::operator+ ( const Vec3 a,
const Vec3 b 
)
noexcept

Adds two Vec3 vectors component-wise.

Definition at line 220 of file geometry_ops.h.

220{ return {a.x + b.x, a.y + b.y, a.z + b.z}; }

◆ operator-() [1/4]

Coord math::operator- ( const Coord a,
const Coord b 
)
noexcept

Subtracts two Coord objects' positions and copies the time.

Definition at line 55 of file coord.h.

55{ return {a.pos - b.pos, a.t}; }

References math::Coord::pos.

◆ operator-() [2/4]

RotationCoord math::operator- ( const RotationCoord a,
const RotationCoord b 
)
noexcept

Subtracts two RotationCoord objects' components and copies the time.

Definition at line 130 of file coord.h.

131 {
132 return {a.azimuth - b.azimuth, a.elevation - b.elevation, a.t};
133 }

References math::Coord::t.

◆ operator-() [3/4]

SVec3 math::operator- ( const SVec3 a,
const SVec3 b 
)
noexcept

Subtracts two SVec3 vectors.

Definition at line 102 of file geometry_ops.cpp.

103 {
104 RealType new_azimuth = a.azimuth - b.azimuth;
105
106 // Wrap the azimuth to the range [-PI, PI] to find the shortest angle
107 // TODO: Has to be a better way to do this...
108 while (new_azimuth <= -PI)
109 new_azimuth += 2 * PI;
110 while (new_azimuth > PI)
111 new_azimuth -= 2 * PI;
112
113 // Elevation difference is typically simpler and doesn't need wrapping
114 // unless 180 degree elevation sweeps are expected.
115 RealType new_elevation = fmod(a.elevation - b.elevation, PI);
116 return {a.length - b.length, new_azimuth, new_elevation};
117 }

References PI.

◆ operator-() [4/4]

Vec3 math::operator- ( const Vec3 a,
const Vec3 b 
)
noexcept

Subtracts two Vec3 vectors component-wise.

Definition at line 223 of file geometry_ops.h.

223{ return {a.x - b.x, a.y - b.y, a.z - b.z}; }

◆ operator/() [1/9]

Coord math::operator/ ( const Coord a,
const Coord b 
)
noexcept

Divides two Coord objects' positions and copies the time.

Definition at line 57 of file coord.h.

57{ return {a.pos / b.pos, a.t}; }

References math::Coord::pos.

◆ operator/() [2/9]

Coord math::operator/ ( const Coord b,
const RealType  a 
)
noexcept

Divides a Coord's position by a scalar while copying the time.

Definition at line 65 of file coord.h.

65{ return {b.pos / a, b.t}; }

References math::Coord::pos.

◆ operator/() [3/9]

Coord math::operator/ ( const RealType  a,
const Coord b 
)
noexcept

Divides a scalar by a Coord's position and copies the time.

Definition at line 63 of file coord.h.

63{ return {a / b.pos, b.t}; }

References math::Coord::pos.

◆ operator/() [4/9]

RotationCoord math::operator/ ( const RealType  a,
const RotationCoord b 
)
noexcept

Divides a scalar by a RotationCoord's components and copies the time.

Definition at line 154 of file coord.h.

155 {
156 return {a / b.azimuth, a / b.elevation, b.t};
157 }

References math::Coord::t.

◆ operator/() [5/9]

Vec3 math::operator/ ( const RealType  a,
const Vec3 b 
)
noexcept

Divides a scalar value by a Vec3 vector.

Definition at line 235 of file geometry_ops.h.

235{ return {a / b.x, a / b.y, a / b.z}; }

◆ operator/() [6/9]

RotationCoord math::operator/ ( const RotationCoord a,
const RotationCoord b 
)
noexcept

Divides two RotationCoord objects' components and copies the time.

Definition at line 136 of file coord.h.

137 {
138 return {a.azimuth / b.azimuth, a.elevation / b.elevation, a.t};
139 }

References math::Coord::t.

◆ operator/() [7/9]

RotationCoord math::operator/ ( const RotationCoord b,
const RealType  a 
)
noexcept

Divides a RotationCoord's components by a scalar while copying the time.

Definition at line 160 of file coord.h.

161 {
162 return {b.azimuth / a, b.elevation / a, b.t};
163 }

References math::Coord::t.

◆ operator/() [8/9]

Vec3 math::operator/ ( const Vec3 a,
const RealType  b 
)
noexcept

Divides a Vec3 vector by a scalar value.

Definition at line 232 of file geometry_ops.h.

232{ return {a.x / b, a.y / b, a.z / b}; }

◆ operator/() [9/9]

Vec3 math::operator/ ( const Vec3 a,
const Vec3 b 
)

Divides two Vec3 vectors component-wise.

Definition at line 226 of file geometry_ops.h.

226{ return {a.x / b.x, a.y / b.y, a.z / b.z}; }

References math::Vec3::x, math::Vec3::y, and math::Vec3::z.

◆ to_json() [1/3]

void math::to_json ( nlohmann::json &  j,
const Coord c 
)

Definition at line 50 of file json_serializer.cpp.

51 {
52 j = {{"time", c.t}, {"x", c.pos.x}, {"y", c.pos.y}, {"altitude", c.pos.z}};
53 }
RealType c() noexcept
Get the speed of light.
Definition parameters.h:79

◆ to_json() [2/3]

void math::to_json ( nlohmann::json &  j,
const RotationCoord rc 
)

Definition at line 63 of file json_serializer.cpp.

64 {
65 // The internal engine uses mathematical angles (radians, CCW from East),
66 // but the UI and XML format use compass degrees (CW from North).
67 // We intentionally DO NOT normalize the output (no fmod) to preserve
68 // negative angles or multi-turn rotations (winding) defined by the user.
69 const RealType az_deg = 90.0 - rc.azimuth * 180.0 / PI;
70 const RealType el_deg = rc.elevation * 180.0 / PI;
71 j = {{"time", rc.t}, {"azimuth", az_deg}, {"elevation", el_deg}};
72 }

References math::RotationCoord::azimuth, math::RotationCoord::elevation, PI, and math::RotationCoord::t.

◆ to_json() [3/3]

void math::to_json ( nlohmann::json &  j,
const Vec3 v 
)

Definition at line 41 of file json_serializer.cpp.

41{ j = {{"x", v.x}, {"y", v.y}, {"z", v.z}}; }

References math::Vec3::x, math::Vec3::y, and math::Vec3::z.