FERS 1.0.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
59 SVec3() noexcept = default;
60 SVec3(const SVec3&) noexcept = default;
61 SVec3(SVec3&&) noexcept = default;
62 SVec3& operator=(const SVec3&) noexcept = default;
63 SVec3& operator=(SVec3&&) noexcept = default;
64
65 /**
66 * @brief Parameterized constructor for SVec3.
67 *
68 * @param vector_length The length or magnitude of the vector.
69 * @param vector_azimuth The azimuthal angle of the vector.
70 * @param vector_elevation The elevation angle of the vector.
71 */
72 constexpr SVec3(const RealType vector_length, const RealType vector_azimuth,
73 const RealType vector_elevation) noexcept :
74 length(vector_length), azimuth(vector_azimuth), elevation(vector_elevation)
75 {
76 }
77
78 /**
79 * @brief Constructs a spherical vector from a rectangular Vec3.
80 *
81 * @param vec A rectangular vector (Vec3) to convert.
82 */
83 explicit SVec3(const Vec3& vec) noexcept;
84
85 /**
86 * @brief Scalar multiplication assignment for SVec3.
87 *
88 * @param b The scalar value.
89 * @return A reference to the updated SVec3.
90 */
91 SVec3& operator*=(RealType b) noexcept;
92
93 /**
94 * @brief Scalar division assignment for SVec3.
95 *
96 * @param b The scalar value.
97 * @return A reference to the updated SVec3.
98 */
99 SVec3& operator/=(RealType b) noexcept;
100 };
101
102 /**
103 * @class Vec3
104 * @brief A class representing a vector in rectangular coordinates.
105 */
106 class Vec3
107 {
108 public:
109 RealType x{}; ///< The x component of the vector
110 RealType y{}; ///< The y component of the vector
111 RealType z{}; ///< The z component of the vector
112
118
119 /**
120 * @brief Parameterized constructor for Vec3.
121 *
122 * @param x_value The x component.
123 * @param y_value The y component.
124 * @param z_value The z component.
125 */
130
131 /**
132 * @brief Constructs a rectangular vector from a spherical SVec3.
133 *
134 * @param svec A spherical vector (SVec3) to convert.
135 */
136 explicit Vec3(const SVec3& svec) noexcept;
137
138 /**
139 * @brief Addition assignment operator for Vec3.
140 *
141 * @param b The vector to add.
142 * @return A reference to the updated Vec3.
143 */
144 Vec3& operator+=(const Vec3& b) noexcept;
145
146 /**
147 * @brief Subtraction assignment operator for Vec3.
148 *
149 * @param b The vector to subtract.
150 * @return A reference to the updated Vec3.
151 */
152 Vec3& operator-=(const Vec3& b) noexcept;
153
154 /**
155 * @brief Multiplication assignment operator for Vec3.
156 *
157 * @param b The vector to multiply by.
158 * @return A reference to the updated Vec3.
159 */
160 Vec3& operator*=(const Vec3& b) noexcept;
161
162 /**
163 * @brief Matrix multiplication assignment for Vec3.
164 *
165 * @param m The matrix to multiply by.
166 * @return A reference to the updated Vec3.
167 */
168 Vec3& operator*=(const Matrix3& m) noexcept;
169
170 /**
171 * @brief Scalar multiplication assignment for Vec3.
172 *
173 * @param b The scalar value.
174 * @return A reference to the updated Vec3.
175 */
176 Vec3& operator*=(RealType b) noexcept;
177
178 /**
179 * @brief Scalar division assignment for Vec3.
180 *
181 * @param b The scalar value.
182 * @return A reference to the updated Vec3.
183 */
184 Vec3& operator/=(RealType b) noexcept;
185
186 /**
187 * @brief Addition operator for Vec3.
188 *
189 * @param value The scalar value to add.
190 * @return The resulting vector.
191 */
192 Vec3 operator+(const RealType value) const { return {x + value, y + value, z + value}; }
193
194 Vec3 operator-() const { return {-x, -y, -z}; }
195
196 /**
197 * @brief Calculates the length (magnitude) of the vector.
198 *
199 * @return The length of the vector.
200 */
201 [[nodiscard]] RealType length() const noexcept { return std::sqrt(x * x + y * y + z * z); }
202 };
203
204 /**
205 * @brief Computes the dot product of two Vec3 vectors.
206 *
207 * @param a The first vector.
208 * @param b The second vector.
209 * @return The dot product of the vectors.
210 */
211 inline RealType dotProduct(const Vec3& a, const Vec3& b) noexcept { return a.x * b.x + a.y * b.y + a.z * b.z; }
212
213 // Cross product
214 // Note: This function is not used in the codebase
215 /*inline Vec3 crossProduct(const Vec3& a, const Vec3& b) noexcept
216 {
217 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};
218 }*/
219
220 /// Multiplies two Vec3 vectors component-wise
221 inline Vec3 operator*(const Vec3& a, const Vec3& b) noexcept { return {a.x * b.x, a.y * b.y, a.z * b.z}; }
222
223 /// Adds 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 /// Subtracts 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 /// Divides two Vec3 vectors component-wise
230 inline Vec3 operator/(const Vec3& a, const Vec3& b) { return {a.x / b.x, a.y / b.y, a.z / b.z}; }
231
232 /// Multiplies a Vec3 vector by a scalar value
233 inline Vec3 operator*(const Vec3& a, const RealType b) noexcept { return {a.x * b, a.y * b, a.z * b}; }
234
235 /// Divides 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 scalar value by a Vec3 vector
239 inline Vec3 operator/(const RealType a, const Vec3& b) noexcept { return {a / b.x, a / b.y, a / b.z}; }
240
241 /// Adds two SVec3 vectors
242 SVec3 operator+(const SVec3& a, const SVec3& b) noexcept;
243
244 /// Subtracts two SVec3 vectors
245 SVec3 operator-(const SVec3& a, const SVec3& b) noexcept;
246}
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
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