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