FERS 0.1.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 214 of file geometry_ops.h.

214{ return a.x * b.x + a.y * b.y + a.z * b.z; }
RealType b
RealType a

References a, and b.

◆ from_json() [1/5]

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

Definition at line 420 of file json_serializer.cpp.

421 {
422 j.at("time").get_to(c.t);
423 j.at("x").get_to(c.pos.x);
424 j.at("y").get_to(c.pos.y);
425 j.at("altitude").get_to(c.pos.z);
426 }
math::Vec3 max
RealType c

References c, and max.

◆ from_json() [2/5]

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

Definition at line 455 of file json_serializer.cpp.

456 {
457 p.setInterp(j.at("interpolation").get<Path::InterpType>());
458 for (const auto waypoints = j.at("positionwaypoints").get<std::vector<Coord>>(); const auto& wp : waypoints)
459 {
460 p.addCoord(wp);
461 }
462 p.finalize();
463 }
InterpType
Types of interpolation supported by the Path class.
Definition path.h:37

References max.

◆ from_json() [3/5]

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

Definition at line 436 of file json_serializer.cpp.

437 {
438 j.at("time").get_to(rc.t);
440 j.at("azimuth").get<RealType>(), j.at("elevation").get<RealType>(), rc.t, params::rotationAngleUnit());
441 rc.azimuth = external.azimuth;
442 rc.elevation = external.elevation;
443 }
double RealType
Type for real numbers.
Definition config.h:27
RotationAngleUnit rotationAngleUnit() noexcept
Gets the external rotation angle unit.
Definition parameters.h:327
math::RotationCoord external_rotation_to_internal(const RealType azimuth, const RealType elevation, const RealType time, const params::RotationAngleUnit unit) noexcept
Converts external compass azimuth/elevation into internal rotation coordinates.

References serial::rotation_angle_utils::external_rotation_to_internal(), max, and params::rotationAngleUnit().

+ Here is the call graph for this function:

◆ from_json() [4/5]

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

Definition at line 498 of file json_serializer.cpp.

499 {
500 p.setInterp(j.at("interpolation").get<RotationPath::InterpType>());
501 for (const auto waypoints = j.at("rotationwaypoints").get<std::vector<RotationCoord>>();
502 const auto& wp : waypoints)
503 {
504 p.addCoord(wp);
505 }
506 p.finalize();
507 }
InterpType
Enumeration for types of interpolation.

References max.

◆ from_json() [5/5]

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

Definition at line 408 of file json_serializer.cpp.

409 {
410 j.at("x").get_to(v.x);
411 j.at("y").get_to(v.y);
412 j.at("z").get_to(v.z);
413 }
RealType x
The x component of the vector.
RealType z
The z component of the vector.
RealType y
The y component of the vector.

References max, 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 445 of file json_serializer.cpp.

446 {{Path::InterpType::INTERP_STATIC, "static"},
447 {Path::InterpType::INTERP_LINEAR, "linear"},
448 {Path::InterpType::INTERP_CUBIC, "cubic"}})
449
450 void to_json(nlohmann::json& j, const Path& p) // NOLINT(*-use-internal-linkage)
451 {
452 j = {{"interpolation", p.getType()}, {"positionwaypoints", p.getCoords()}};
453 }
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 465 of file json_serializer.cpp.

466 {{RotationPath::InterpType::INTERP_STATIC, "static"},
467 {RotationPath::InterpType::INTERP_CONSTANT,
468 "constant"}, // Not used in xml_parser or UI yet, but for completeness
469 {RotationPath::InterpType::INTERP_LINEAR, "linear"},
470 {RotationPath::InterpType::INTERP_CUBIC, "cubic"}})
471
472 void to_json(nlohmann::json& j, const RotationPath& p) // NOLINT(*-use-internal-linkage)
473 {
474 j["interpolation"] = p.getType();
475 // This logic exists to map the two different rotation definitions from the
476 // XML schema (<fixedrotation> and <rotationpath>) into a unified JSON
477 // structure that the frontend can more easily handle.
478 if (p.getType() == RotationPath::InterpType::INTERP_CONSTANT)
479 {
480 // A constant-rate rotation path corresponds to the <fixedrotation> XML element.
481 // The start and rate values are converted to compass degrees per second.
482 // No normalization is applied to preserve negative start angles.
483 const auto unit = params::rotationAngleUnit();
484 j["startazimuth"] = serial::rotation_angle_utils::internal_azimuth_to_external(p.getStart().azimuth, unit);
485 j["startelevation"] =
487 j["azimuthrate"] =
489 j["elevationrate"] =
491 }
492 else
493 {
494 j["rotationwaypoints"] = p.getCoords();
495 }
496 }
RealType internal_elevation_to_external(const RealType elevation, const params::RotationAngleUnit unit) noexcept
Converts an internal elevation angle to the external unit.
RealType internal_azimuth_rate_to_external(const RealType azimuth_rate, const params::RotationAngleUnit unit) noexcept
Converts an internal azimuth rate to the external compass convention.
RealType internal_elevation_rate_to_external(const RealType elevation_rate, const params::RotationAngleUnit unit) noexcept
Converts an internal elevation rate to the external unit.
RealType internal_azimuth_to_external(const RealType azimuth, const params::RotationAngleUnit unit) noexcept
Converts an internal azimuth angle to the external compass convention.

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}; }

References a, b, and 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 a, b, and 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 a, b, and 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 a, b, and 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 236 of file geometry_ops.h.

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

References a, and b.

◆ operator*() [6/6]

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

Multiplies two Vec3 vectors component-wise.

Definition at line 224 of file geometry_ops.h.

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

References a, and b.

◆ 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 a, b, and 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 a, b, and 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 a, b, and 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 a, b, and math::Coord::t.

◆ operator+() [5/6]

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

Adds two SVec3 vectors.

Definition at line 117 of file geometry_ops.cpp.

118 {
119 const RealType new_azimuth = wrapSignedAngle(a.azimuth + b.azimuth);
120 const RealType new_elevation = std::fmod(a.elevation + b.elevation, PI);
121
122 return {a.length + b.length, new_azimuth, new_elevation};
123 }
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43

References a, b, max, and PI.

◆ operator+() [6/6]

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

Adds two Vec3 vectors component-wise.

Definition at line 227 of file geometry_ops.h.

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

References a, and b.

◆ 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 a, b, and 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 a, b, and math::Coord::t.

◆ operator-() [3/4]

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

Subtracts two SVec3 vectors.

Definition at line 125 of file geometry_ops.cpp.

126 {
127 const RealType new_azimuth = wrapSignedAngle(a.azimuth - b.azimuth);
128
129 // Elevation difference is typically simpler and doesn't need wrapping
130 // unless 180 degree elevation sweeps are expected.
131 const RealType new_elevation = std::fmod(a.elevation - b.elevation, PI);
132
133 return {a.length - b.length, new_azimuth, new_elevation};
134 }

References a, b, max, and PI.

◆ operator-() [4/4]

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

Subtracts two Vec3 vectors component-wise.

Definition at line 230 of file geometry_ops.h.

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

References a, and b.

◆ 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 a, b, and 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 a, b, and 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 a, b, and 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 a, b, and 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 242 of file geometry_ops.h.

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

References a, and b.

◆ 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 a, b, and 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 a, b, and 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 239 of file geometry_ops.h.

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

References a, and b.

◆ operator/() [9/9]

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

Divides two Vec3 vectors component-wise.

Definition at line 233 of file geometry_ops.h.

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

References a, and b.

◆ to_json() [1/3]

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

Definition at line 415 of file json_serializer.cpp.

416 {
417 j = {{"time", c.t}, {"x", c.pos.x}, {"y", c.pos.y}, {"altitude", c.pos.z}};
418 }

References c, max, and math::Vec3::x.

◆ to_json() [2/3]

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

Definition at line 428 of file json_serializer.cpp.

429 {
430 const auto unit = params::rotationAngleUnit();
431 j = {{"time", rc.t},
434 }

References serial::rotation_angle_utils::internal_azimuth_to_external(), serial::rotation_angle_utils::internal_elevation_to_external(), max, and params::rotationAngleUnit().

+ Here is the call graph for this function:

◆ to_json() [3/3]

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

Definition at line 403 of file json_serializer.cpp.

404 {
405 j = {{"x", v.x}, {"y", v.y}, {"z", v.z}};
406 } // NOLINT(*-use-internal-linkage)

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