FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
geometry_ops.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 geometry_ops.h
10 * @brief Classes and operations for 3D geometry.
11 */
12
13#pragma once
14
15#include <array>
16#include <cmath>
17
18#include "core/config.h"
19
20namespace math
21{
22 class Vec3;
23
24 /**
25 * @class Matrix3
26 * @brief A class representing a 3x3 matrix.
27 */
28 class Matrix3
29 {
30 public:
31 std::array<RealType, 9> elements{}; ///< The 3x3 matrix elements
32
33 /**
34 * @brief Get the matrix data as a constant pointer.
35 *
36 * @return A constant pointer to the matrix elements.
37 */
38 [[nodiscard]] const RealType* getData() const noexcept { return elements.data(); }
39
40 /**
41 * @brief Get the matrix data as a modifiable pointer.
42 *
43 * @return A pointer to the matrix elements.
44 */
45 RealType* getData() noexcept { return elements.data(); }
46 };
47
48 /**
49 * @class SVec3
50 * @brief A class representing a vector in spherical coordinates.
51 */
52 class SVec3
53 {
54 public:
55 RealType length{}; ///< The length of the vector
56 RealType azimuth{}; ///< The azimuth angle of the vector
57 RealType elevation{}; ///< The elevation angle of the vector
58
65
66 /**
67 * @brief Parameterized constructor for SVec3.
68 *
69 * @param vector_length The length or magnitude of the vector.
70 * @param vector_azimuth The azimuthal angle of the vector.
71 * @param vector_elevation The elevation angle of the vector.
72 */
78
79 /**
80 * @brief Constructs a spherical vector from a rectangular Vec3.
81 *
82 * @param vec A rectangular vector (Vec3) to convert.
83 */
84 explicit SVec3(const Vec3& vec) noexcept;
85
86 /**
87 * @brief Scalar multiplication assignment for SVec3.
88 *
89 * @param b The scalar value.
90 * @return A reference to the updated SVec3.
91 */
92 SVec3& operator*=(RealType b) noexcept;
93
94 /**
95 * @brief Scalar division assignment for SVec3.
96 *
97 * @param b The scalar value.
98 * @return A reference to the updated SVec3.
99 */
100 SVec3& operator/=(RealType b) noexcept;
101 };
102
103 /**
104 * @class Vec3
105 * @brief A class representing a vector in rectangular coordinates.
106 */
107 class Vec3
108 {
109 public:
110 RealType x{}; ///< The x component of the vector
111 RealType y{}; ///< The y component of the vector
112 RealType z{}; ///< The z component of the vector
113
120
121 /**
122 * @brief Parameterized constructor for Vec3.
123 *
124 * @param x_value The x component.
125 * @param y_value The y component.
126 * @param z_value The z component.
127 */
132
133 /**
134 * @brief Constructs a rectangular vector from a spherical SVec3.
135 *
136 * @param svec A spherical vector (SVec3) to convert.
137 */
138 explicit Vec3(const SVec3& svec) noexcept;
139
140 /**
141 * @brief Addition assignment operator for Vec3.
142 *
143 * @param b The vector to add.
144 * @return A reference to the updated Vec3.
145 */
146 Vec3& operator+=(const Vec3& b) noexcept;
147
148 /**
149 * @brief Subtraction assignment operator for Vec3.
150 *
151 * @param b The vector to subtract.
152 * @return A reference to the updated Vec3.
153 */
154 Vec3& operator-=(const Vec3& b) noexcept;
155
156 /**
157 * @brief Multiplication assignment operator for Vec3.
158 *
159 * @param b The vector to multiply by.
160 * @return A reference to the updated Vec3.
161 */
162 Vec3& operator*=(const Vec3& b) noexcept;
163
164 /**
165 * @brief Matrix multiplication assignment for Vec3.
166 *
167 * @param m The matrix to multiply by.
168 * @return A reference to the updated Vec3.
169 */
170 Vec3& operator*=(const Matrix3& m) noexcept;
171
172 /**
173 * @brief Scalar multiplication assignment for Vec3.
174 *
175 * @param b The scalar value.
176 * @return A reference to the updated Vec3.
177 */
178 Vec3& operator*=(RealType b) noexcept;
179
180 /**
181 * @brief Scalar division assignment for Vec3.
182 *
183 * @param b The scalar value.
184 * @return A reference to the updated Vec3.
185 */
186 Vec3& operator/=(RealType b) noexcept;
187
188 /**
189 * @brief Addition operator for Vec3.
190 *
191 * @param value The scalar value to add.
192 * @return The resulting vector.
193 */
194 Vec3 operator+(const RealType value) const { return {x + value, y + value, z + value}; }
195
196 /** @brief Unary negation operator for Vec3. @return The negated vector. */
197 Vec3 operator-() const { return {-x, -y, -z}; }
198
199 /**
200 * @brief Calculates the length (magnitude) of the vector.
201 *
202 * @return The length of the vector.
203 */
204 [[nodiscard]] RealType length() const noexcept { return std::sqrt(x * x + y * y + z * z); }
205 };
206
207 /**
208 * @brief Computes the dot product of two Vec3 vectors.
209 *
210 * @param a The first vector.
211 * @param b The second vector.
212 * @return The dot product of the vectors.
213 */
214 inline RealType dotProduct(const Vec3& a, const Vec3& b) noexcept { return a.x * b.x + a.y * b.y + a.z * b.z; }
215
216 // Cross product
217 // Note: This function is not used in the codebase
218 /*inline Vec3 crossProduct(const Vec3& a, const Vec3& b) noexcept
219 {
220 return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
221 }*/
222
223 /// Multiplies two Vec3 vectors component-wise
224 inline Vec3 operator*(const Vec3& a, const Vec3& b) noexcept { return {a.x * b.x, a.y * b.y, a.z * b.z}; }
225
226 /// Adds two Vec3 vectors component-wise
227 inline Vec3 operator+(const Vec3& a, const Vec3& b) noexcept { return {a.x + b.x, a.y + b.y, a.z + b.z}; }
228
229 /// Subtracts two Vec3 vectors component-wise
230 inline Vec3 operator-(const Vec3& a, const Vec3& b) noexcept { return {a.x - b.x, a.y - b.y, a.z - b.z}; }
231
232 /// Divides two Vec3 vectors component-wise
233 inline Vec3 operator/(const Vec3& a, const Vec3& b) { return {a.x / b.x, a.y / b.y, a.z / b.z}; }
234
235 /// Multiplies a Vec3 vector by a scalar value
236 inline Vec3 operator*(const Vec3& a, const RealType b) noexcept { return {a.x * b, a.y * b, a.z * b}; }
237
238 /// Divides a Vec3 vector by a scalar value
239 inline Vec3 operator/(const Vec3& a, const RealType b) noexcept { return {a.x / b, a.y / b, a.z / b}; }
240
241 /// Divides a scalar value by a Vec3 vector
242 inline Vec3 operator/(const RealType a, const Vec3& b) noexcept { return {a / b.x, a / b.y, a / b.z}; }
243
244 /// Adds two SVec3 vectors
245 SVec3 operator+(const SVec3& a, const SVec3& b) noexcept;
246
247 /// Subtracts two SVec3 vectors
248 SVec3 operator-(const SVec3& a, const SVec3& b) noexcept;
249}
A class representing a 3x3 matrix.
RealType * getData() noexcept
Get the matrix data as a modifiable pointer.
std::array< RealType, 9 > elements
The 3x3 matrix elements.
const RealType * getData() const noexcept
Get the matrix data as a constant pointer.
A class representing a vector in spherical coordinates.
RealType elevation
The elevation angle of the vector.
RealType azimuth
The azimuth angle of the vector.
RealType length
The length of the vector.
SVec3() noexcept=default
SVec3 & operator/=(RealType b) noexcept
Scalar division assignment for SVec3.
SVec3 & operator*=(RealType b) noexcept
Scalar multiplication assignment for SVec3.
A class representing a vector in rectangular coordinates.
RealType x
The x component of the vector.
RealType z
The z component of the vector.
Vec3 & operator-=(const Vec3 &b) noexcept
Subtraction assignment operator for Vec3.
RealType length() const noexcept
Calculates the length (magnitude) of the vector.
RealType y
The y component of the vector.
Vec3 & operator+=(const Vec3 &b) noexcept
Addition assignment operator for Vec3.
Vec3 & operator/=(RealType b) noexcept
Scalar division assignment for Vec3.
Vec3 operator-() const
Unary negation operator for Vec3.
Vec3 operator+(const RealType value) const
Addition operator for Vec3.
Vec3() noexcept=default
Vec3 & operator*=(const Vec3 &b) noexcept
Multiplication assignment operator for Vec3.
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
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
RealType dotProduct(const Vec3 &a, const Vec3 &b) noexcept
Computes the dot product of two Vec3 vectors.
Coord operator*(const Coord &a, const Coord &b) noexcept
Multiplies two Coord objects' positions and copies the time.
Definition coord.h:51
math::Vec3 max
RealType b
RealType a