FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
coord.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file coord.h
10 * @brief Coordinate and rotation structure operations.
11 */
12
13#pragma once
14
15#include "geometry_ops.h"
16
17namespace math
18{
19 /**
20 * @class Coord
21 * @brief Represents a position in 3D space with an associated time.
22 */
23 struct Coord
24 {
25 Vec3 pos; ///< 3D position
26 RealType t; ///< Time
27
28 /**
29 * @brief Comparison operator based on the time component.
30 *
31 * @param b The other `Coord` to compare.
32 * @return True if the current object's time is less than the other.
33 */
34 bool operator<(const Coord& b) const noexcept { return t < b.t; }
35
36 /**
37 * @brief Assignment operator to set the time and position.
38 *
39 * @param a Scalar value to assign to the position and time.
40 * @return Reference to the modified `Coord` object.
41 */
43 {
44 t = a;
45 pos = {a, a, a};
46 return *this;
47 }
48 };
49
50 /// Multiplies two `Coord` objects' positions and copies the time.
51 inline Coord operator*(const Coord& a, const Coord& b) noexcept { return {a.pos * b.pos, a.t}; }
52 /// Adds two `Coord` objects' positions and copies the time.
53 inline Coord operator+(const Coord& a, const Coord& b) noexcept { return {a.pos + b.pos, a.t}; }
54 /// Subtracts two `Coord` objects' positions and copies the time.
55 inline Coord operator-(const Coord& a, const Coord& b) noexcept { return {a.pos - b.pos, a.t}; }
56 /// Divides two `Coord` objects' positions and copies the time.
57 inline Coord operator/(const Coord& a, const Coord& b) noexcept { return {a.pos / b.pos, a.t}; }
58 /// Adds a scalar to a `Coord`'s position while copying the time.
59 inline Coord operator+(const Coord& a, const RealType b) noexcept { return {a.pos + b, a.t}; }
60 /// Multiplies a `Coord`'s position by a scalar while copying the time.
61 inline Coord operator*(const Coord& a, const RealType b) noexcept { return {a.pos * b, a.t}; }
62 /// Divides a scalar by a `Coord`'s position and copies the time.
63 inline Coord operator/(const RealType a, const Coord& b) noexcept { return {a / b.pos, b.t}; }
64 /// Divides a `Coord`'s position by a scalar while copying the time.
65 inline Coord operator/(const Coord& b, const RealType a) noexcept { return {b.pos / a, b.t}; }
66
67 /**
68 * @class RotationCoord
69 * @brief Represents a rotation in terms of azimuth, elevation, and time.
70 */
72 {
73 RealType azimuth{}; ///< Azimuth angle
74 RealType elevation{}; ///< Elevation angle
75 RealType t{}; ///< Time
76
77 /**
78 * @brief Comparison operator based on the time component.
79 *
80 * @param b The other `RotationCoord` to compare.
81 * @return True if the current object's time is less than the other.
82 */
83 bool operator<(const RotationCoord& b) const noexcept { return t < b.t; }
84
85 /**
86 * @brief Assignment operator to set azimuth, elevation, and time.
87 *
88 * @param a Scalar value to assign to all components.
89 * @return Reference to the modified `RotationCoord` object.
90 */
91 RotationCoord& operator=(const RealType a) noexcept
92 {
93 azimuth = elevation = t = a;
94 return *this;
95 }
96
97 /**
98 * @brief Constructor to initialize azimuth, elevation, and time.
99 *
100 * @param a Scalar value to initialize azimuth, elevation, and time.
101 */
102 constexpr explicit RotationCoord(const RealType a = 0) noexcept : azimuth(a), elevation(a), t(a) {}
103
104 /**
105 * @brief Constructor to initialize azimuth, elevation, and time.
106 *
107 * @param az Azimuth angle.
108 * @param el Elevation angle.
109 * @param time Time component.
110 */
111 RotationCoord(const RealType az, const RealType el, const RealType time) noexcept :
112 azimuth(az), elevation(el), t(time)
113 {
114 }
115 };
116
117 /// Multiplies two `RotationCoord` objects' components and copies the time.
118 inline RotationCoord operator*(const RotationCoord& a, const RotationCoord& b) noexcept
119 {
120 return {a.azimuth * b.azimuth, a.elevation * b.elevation, a.t};
121 }
122
123 /// Adds two `RotationCoord` objects' components and copies the time.
124 inline RotationCoord operator+(const RotationCoord& a, const RotationCoord& b) noexcept
125 {
126 return {a.azimuth + b.azimuth, a.elevation + b.elevation, a.t};
127 }
128
129 /// Subtracts two `RotationCoord` objects' components and copies the time.
130 inline RotationCoord operator-(const RotationCoord& a, const RotationCoord& b) noexcept
131 {
132 return {a.azimuth - b.azimuth, a.elevation - b.elevation, a.t};
133 }
134
135 /// Divides two `RotationCoord` objects' components and copies the time.
136 inline RotationCoord operator/(const RotationCoord& a, const RotationCoord& b) noexcept
137 {
138 return {a.azimuth / b.azimuth, a.elevation / b.elevation, a.t};
139 }
140
141 /// Adds a scalar to a `RotationCoord`'s components while copying the time.
142 inline RotationCoord operator+(const RotationCoord& a, const RealType b) noexcept
143 {
144 return {a.azimuth + b, a.elevation + b, a.t};
145 }
146
147 /// Multiplies a `RotationCoord`'s components by a scalar while copying the time.
148 inline RotationCoord operator*(const RotationCoord& a, const RealType b) noexcept
149 {
150 return {a.azimuth * b, a.elevation * b, a.t};
151 }
152
153 /// Divides a scalar by a `RotationCoord`'s components and copies the time.
154 inline RotationCoord operator/(const RealType a, const RotationCoord& b) noexcept
155 {
156 return {a / b.azimuth, a / b.elevation, b.t};
157 }
158
159 /// Divides a `RotationCoord`'s components by a scalar while copying the time.
160 inline RotationCoord operator/(const RotationCoord& b, const RealType a) noexcept
161 {
162 return {b.azimuth / a, b.elevation / a, b.t};
163 }
164}
A class representing a vector in rectangular coordinates.
double RealType
Type for real numbers.
Definition config.h:27
Classes and operations for 3D geometry.
Definition coord.h:18
Coord operator+(const Coord &a, const Coord &b) noexcept
Adds two Coord objects' positions and copies the time.
Definition coord.h:53
Coord operator-(const Coord &a, const Coord &b) noexcept
Subtracts two Coord objects' positions and copies the time.
Definition coord.h:55
Coord operator/(const Coord &a, const Coord &b) noexcept
Divides two Coord objects' positions and copies the time.
Definition coord.h:57
Coord operator*(const Coord &a, const Coord &b) noexcept
Multiplies two Coord objects' positions and copies the time.
Definition coord.h:51
Represents a position in 3D space with an associated time.
Definition coord.h:24
Coord & operator=(RealType a) noexcept
Assignment operator to set the time and position.
Definition coord.h:42
RealType t
Time.
Definition coord.h:26
bool operator<(const Coord &b) const noexcept
Comparison operator based on the time component.
Definition coord.h:34
Vec3 pos
3D position
Definition coord.h:25
Represents a rotation in terms of azimuth, elevation, and time.
Definition coord.h:72
RealType t
Time.
Definition coord.h:75
RealType elevation
Elevation angle.
Definition coord.h:74
RotationCoord(const RealType az, const RealType el, const RealType time) noexcept
Constructor to initialize azimuth, elevation, and time.
Definition coord.h:111
RealType azimuth
Azimuth angle.
Definition coord.h:73
RotationCoord & operator=(const RealType a) noexcept
Assignment operator to set azimuth, elevation, and time.
Definition coord.h:91
bool operator<(const RotationCoord &b) const noexcept
Comparison operator based on the time component.
Definition coord.h:83
constexpr RotationCoord(const RealType a=0) noexcept
Constructor to initialize azimuth, elevation, and time.
Definition coord.h:102