A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef NS3_VECTOR_H
9#define NS3_VECTOR_H
10
11#include "attribute-helper.h"
12#include "attribute.h"
13
14/**
15 * @file
16 * @ingroup geometry
17 * ns3::Vector, ns3::Vector2D and ns3::Vector3D declarations.
18 */
19
20namespace ns3
21{
22
23/**
24 * @ingroup core
25 * @defgroup geometry Geometry primitives
26 * @brief Primitives for geometry, such as vectors and angles.
27 */
28
29/**
30 * @ingroup geometry
31 * @brief a 3d vector
32 * @see attribute_Vector3D
33 */
35{
36 public:
37 /**
38 * @param [in] _x X coordinate of vector
39 * @param [in] _y Y coordinate of vector
40 * @param [in] _z Z coordinate of vector
41 *
42 * Create vector (_x, _y, _z)
43 */
44 Vector3D(double _x, double _y, double _z);
45 /** Create vector (0.0, 0.0, 0.0) */
46 Vector3D();
47
48 double x; //!< x coordinate of vector
49 double y; //!< y coordinate of vector
50 double z; //!< z coordinate of vector
51
52 /**
53 * Compute the length (magnitude) of the vector.
54 * @returns the vector length.
55 */
56 double GetLength() const;
57
58 /**
59 * Compute the squared length of the vector.
60 * @returns the vector length squared.
61 */
62 double GetLengthSquared() const;
63
64 /**
65 * @brief Calculate the Cartesian distance between two points.
66 * @param [in] a One point
67 * @param [in] b Another point
68 * @returns The distance between \pname{a} and \pname{b}.
69 */
70 friend double CalculateDistance(const Vector3D& a, const Vector3D& b);
71
72 /**
73 * @brief Calculate the squared Cartesian distance between two points.
74 * @param [in] a One point
75 * @param [in] b Another point
76 * @returns The distance between \pname{a} and \pname{b}.
77 */
78 friend double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
79
80 /**
81 * Output streamer.
82 * Vectors are written as "x:y:z".
83 *
84 * @param [in,out] os The stream.
85 * @param [in] vector The vector to stream
86 * @return The stream.
87 */
88 friend std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
89
90 /**
91 * Input streamer.
92 *
93 * Vectors are expected to be in the form "x:y:z".
94 *
95 * @param [in,out] is The stream.
96 * @param [in] vector The vector.
97 * @returns The stream.
98 */
99 friend std::istream& operator>>(std::istream& is, Vector3D& vector);
100
101 /**
102 * Less than comparison operator
103 * @param [in] a lhs vector
104 * @param [in] b rhs vector
105 * @returns \c true if \pname{a} is less than \pname{b}
106 */
107 friend bool operator<(const Vector3D& a, const Vector3D& b);
108
109 /**
110 * Less than or equal to comparison operator
111 * @param [in] a lhs vector
112 * @param [in] b rhs vector
113 * @returns \c true if \pname{a} is less than or equal to \pname{b}.
114 */
115 friend bool operator<=(const Vector3D& a, const Vector3D& b);
116
117 /**
118 * Greater than comparison operator
119 * @param [in] a lhs vector
120 * @param [in] b rhs vector
121 * @returns \c true if \pname{a} is greater than \pname{b}.
122 */
123 friend bool operator>(const Vector3D& a, const Vector3D& b);
124
125 /**
126 * Greater than or equal to comparison operator
127 * @param [in] a lhs vector
128 * @param [in] b rhs vector
129 * @returns \c true if \pname{a} is greater than or equal to \pname{b}.
130 */
131 friend bool operator>=(const Vector3D& a, const Vector3D& b);
132
133 /**
134 * Equality operator.
135 * @param [in] a lhs vector.
136 * @param [in] b rhs vector.
137 * @returns \c true if \pname{a} is equal to \pname{b}.
138 */
139 friend bool operator==(const Vector3D& a, const Vector3D& b);
140
141 /**
142 * Inequality operator.
143 * @param [in] a lhs vector.
144 * @param [in] b rhs vector.
145 * @returns \c true if \pname{a} is not equal to \pname{b}.
146 */
147 friend bool operator!=(const Vector3D& a, const Vector3D& b);
148
149 /**
150 * Addition operator.
151 * @param [in] a lhs vector.
152 * @param [in] b rhs vector.
153 * @returns The vector sum of \pname{a} and \pname{b}.
154 */
155 friend Vector3D operator+(const Vector3D& a, const Vector3D& b);
156
157 /**
158 * Subtraction operator.
159 * @param [in] a lhs vector.
160 * @param [in] b rhs vector.
161 * @returns The vector difference of \pname{a} and \pname{b}.
162 */
163 friend Vector3D operator-(const Vector3D& a, const Vector3D& b);
164
165 /**
166 * Scalar multiplication operator.
167 * @param [in] a lhs vector.
168 * @param [in] b rhs scalar.
169 * @returns The vector \pname{a} scaled by \pname{b}.
170 */
171 friend Vector3D operator*(const Vector3D& a, double b);
172
173 /**
174 * Scalar multiplication operator.
175 * @param [in] a lhs scalar.
176 * @param [in] b rhs vector.
177 * @returns The vector \pname{b} scaled by \pname{a}.
178 */
179 friend Vector3D operator*(double a, const Vector3D& b);
180
181 /**
182 * Dot product operator.
183 * @param [in] a lhs vector.
184 * @param [in] b rhs vector.
185 * @returns The dot product of \pname{a} and \pname{b}.
186 */
187 friend double operator*(const Vector3D& a, const Vector3D& b);
188
189 /**
190 * Cross product
191 * @param [in] a lhs vector.
192 * @param [in] b rhs vector.
193 * @return The cross product of \pname{a} and \pname{b}
194 */
195 friend Vector3D CrossProduct(const Vector3D& a, const Vector3D& b);
196};
197
198/**
199 * @ingroup geometry
200 * @brief a 2d vector
201 * @see attribute_Vector2D
202 */
204{
205 public:
206 /**
207 * @param [in] _x X coordinate of vector
208 * @param [in] _y Y coordinate of vector
209 *
210 * Create vector (_x, _y)
211 */
212 Vector2D(double _x, double _y);
213 /** Constructor: (0.0, 0.0) */
214 Vector2D();
215 double x; //!< x coordinate of vector
216 double y; //!< y coordinate of vector
217
218 // works: /** \copydoc ns3::Vector3D::GetLength() */
219 /** @copydoc Vector3D::GetLength() */
220 double GetLength() const;
221
222 /** @copydoc Vector3D::GetLengthSquared() */
223 double GetLengthSquared() const;
224
225 /**
226 * @brief Calculate the Cartesian distance between two points.
227 * @param [in] a One point
228 * @param [in] b Another point
229 * @returns The distance between \pname{a} and \pname{b}.
230 */
231 friend double CalculateDistance(const Vector2D& a, const Vector2D& b);
232
233 /**
234 * @brief Calculate the squared Cartesian distance between two points.
235 * @param [in] a One point
236 * @param [in] b Another point
237 * @returns The distance between \pname{a} and \pname{b}.
238 */
239 friend double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
240
241 /**
242 * Output streamer.
243 * Vectors are written as "x:y".
244 *
245 * @param [in,out] os The stream.
246 * @param [in] vector The vector to stream
247 * @return The stream.
248 */
249 friend std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
250
251 /**
252 * Input streamer.
253 *
254 * Vectors are expected to be in the form "x:y".
255 *
256 * @param [in,out] is The stream.
257 * @param [in] vector The vector.
258 * @returns The stream.
259 */
260 friend std::istream& operator>>(std::istream& is, Vector2D& vector);
261
262 /**
263 * Less than comparison operator
264 * @param [in] a lhs vector
265 * @param [in] b rhs vector
266 * @returns \c true if \pname{a} is less than \pname{b}
267 */
268 friend bool operator<(const Vector2D& a, const Vector2D& b);
269
270 /**
271 * Less than or equal to comparison operator
272 * @param [in] a lhs vector
273 * @param [in] b rhs vector
274 * @returns \c true if \pname{a} is less than or equal to \pname{b}.
275 */
276 friend bool operator<=(const Vector2D& a, const Vector2D& b);
277
278 /**
279 * Greater than comparison operator
280 * @param [in] a lhs vector
281 * @param [in] b rhs vector
282 * @returns \c true if \pname{a} is greater than \pname{b}.
283 */
284 friend bool operator>(const Vector2D& a, const Vector2D& b);
285
286 /**
287 * Greater than or equal to comparison operator
288 * @param [in] a lhs vector
289 * @param [in] b rhs vector
290 * @returns \c true if \pname{a} is greater than or equal to \pname{b}.
291 */
292 friend bool operator>=(const Vector2D& a, const Vector2D& b);
293
294 /**
295 * Equality operator.
296 * @param [in] a lhs vector.
297 * @param [in] b rhs vector.
298 * @returns \c true if \pname{a} is equal to \pname{b}.
299 */
300 friend bool operator==(const Vector2D& a, const Vector2D& b);
301
302 /**
303 * Inequality operator.
304 * @param [in] a lhs vector.
305 * @param [in] b rhs vector.
306 * @returns \c true if \pname{a} is not equal to \pname{b}.
307 */
308 friend bool operator!=(const Vector2D& a, const Vector2D& b);
309
310 /**
311 * Addition operator.
312 * @param [in] a lhs vector.
313 * @param [in] b rhs vector.
314 * @returns The vector sum of \pname{a} and \pname{b}.
315 */
316 friend Vector2D operator+(const Vector2D& a, const Vector2D& b);
317
318 /**
319 * Subtraction operator.
320 * @param [in] a lhs vector.
321 * @param [in] b rhs vector.
322 * @returns The vector difference of \pname{a} and \pname{b}.
323 */
324 friend Vector2D operator-(const Vector2D& a, const Vector2D& b);
325
326 /**
327 * Scalar multiplication operator.
328 * @param [in] a lhs vector.
329 * @param [in] b rhs scalar.
330 * @returns The vector \pname{a} scaled by \pname{b}.
331 */
332 friend Vector2D operator*(const Vector2D& a, double b);
333
334 /**
335 * Scalar multiplication operator.
336 * @param [in] a lhs scalar.
337 * @param [in] b rhs vector.
338 * @returns The vector \pname{b} scaled by \pname{a}.
339 */
340 friend Vector2D operator*(double a, const Vector2D& b);
341
342 /**
343 * Dot product operator.
344 * @param [in] a lhs vector.
345 * @param [in] b rhs vector.
346 * @returns The dot product of \pname{a} and \pname{b}.
347 */
348 friend double operator*(const Vector2D& a, const Vector2D& b);
349
350 /**
351 * Cross product
352 * @param [in] a lhs vector.
353 * @param [in] b rhs vector.
354 * @return The cross product of \pname{a} and \pname{b} @$ a_x b_y - a_y b_x @$
355 */
356 friend double CrossProduct(const Vector2D& a, const Vector2D& b);
357};
358
359double CalculateDistance(const Vector3D& a, const Vector3D& b);
360double CalculateDistance(const Vector2D& a, const Vector2D& b);
361double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
362double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
363std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
364std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
365std::istream& operator>>(std::istream& is, Vector3D& vector);
366std::istream& operator>>(std::istream& is, Vector2D& vector);
367bool operator<(const Vector3D& a, const Vector3D& b);
368bool operator<(const Vector2D& a, const Vector2D& b);
369
372
373/**
374 * @ingroup attribute_Vector3D
375 * @relates Vector3D
376 * Vector alias typedef for compatibility with mobility models
377 */
379
380/**
381 * @ingroup attribute_Vector3D
382 * @relates Vector3D
383 * Vector alias typedef for compatibility with mobility models
384 */
386
387/**
388 * @ingroup attribute_Vector3D
389 * @relates Vector3D
390 * Vector alias typedef for compatibility with mobility models
391 */
393
395
397
398} // namespace ns3
399
400// Document these by hand so they go in group attribute_Vector3D
401
402/**
403 * @ingroup attribute_Vector3D
404 * \fn ns3::Ptr<const ns3::AttributeAccessor> ns3::MakeVectorAccessor (T1 a1)
405 * @copydoc ns3::MakeAccessorHelper(T1)
406 * @see AttributeAccessor
407 */
408
409/**
410 * @ingroup attribute_Vector3D
411 * \fn ns3::Ptr<const ns3::AttributeAccessor> ns3::MakeVectorAccessor (T1 a1, T2 a2)
412 * @copydoc ns3::MakeAccessorHelper(T1,T2)
413 * @see AttributeAccessor
414 */
415
416/**
417 * @ingroup attribute_Vector3D
418 * \fn ns3::Ptr<const ns3::AttributeChecker> ns3::MakeVectorChecker ()
419 * @returns The AttributeChecker.
420 * @see AttributeChecker
421 */
422
423#endif /* NS3_VECTOR_H */
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a 2d vector
Definition vector.h:204
Vector2D(double _x, double _y)
Definition vector.cc:53
friend bool operator!=(const Vector2D &a, const Vector2D &b)
Inequality operator.
Definition vector.cc:265
friend double CalculateDistanceSquared(const Vector2D &a, const Vector2D &b)
Calculate the squared Cartesian distance between two points.
Definition vector.cc:117
friend std::istream & operator>>(std::istream &is, Vector2D &vector)
Input streamer.
Definition vector.cc:223
double y
y coordinate of vector
Definition vector.h:216
friend bool operator==(const Vector2D &a, const Vector2D &b)
Equality operator.
Definition vector.cc:259
friend bool operator<=(const Vector2D &a, const Vector2D &b)
Less than or equal to comparison operator.
Definition vector.cc:241
Vector2D()
Constructor: (0.0, 0.0).
Definition vector.cc:60
friend bool operator<(const Vector2D &a, const Vector2D &b)
Less than comparison operator.
Definition vector.cc:235
friend std::ostream & operator<<(std::ostream &os, const Vector2D &vector)
Output streamer.
Definition vector.cc:216
double x
x coordinate of vector
Definition vector.h:215
friend Vector2D operator+(const Vector2D &a, const Vector2D &b)
Addition operator.
Definition vector.cc:271
friend bool operator>(const Vector2D &a, const Vector2D &b)
Greater than comparison operator.
Definition vector.cc:247
friend bool operator>=(const Vector2D &a, const Vector2D &b)
Greater than or equal to comparison operator.
Definition vector.cc:253
friend Vector2D operator-(const Vector2D &a, const Vector2D &b)
Subtraction operator.
Definition vector.cc:277
double GetLength() const
Compute the length (magnitude) of the vector.
Definition vector.cc:75
friend Vector2D operator*(const Vector2D &a, double b)
Scalar multiplication operator.
Definition vector.cc:283
friend double CalculateDistance(const Vector2D &a, const Vector2D &b)
Calculate the Cartesian distance between two points.
Definition vector.cc:103
friend double CrossProduct(const Vector2D &a, const Vector2D &b)
Cross product.
Definition vector.cc:301
double GetLengthSquared() const
Compute the squared length of the vector.
Definition vector.cc:89
a 3d vector
Definition vector.h:35
double GetLength() const
Compute the length (magnitude) of the vector.
Definition vector.cc:68
Vector3D(double _x, double _y, double _z)
Definition vector.cc:37
friend double CalculateDistance(const Vector3D &a, const Vector3D &b)
Calculate the Cartesian distance between two points.
Definition vector.cc:96
friend std::ostream & operator<<(std::ostream &os, const Vector3D &vector)
Output streamer.
Definition vector.cc:124
friend bool operator>=(const Vector3D &a, const Vector3D &b)
Greater than or equal to comparison operator.
Definition vector.cc:162
friend bool operator!=(const Vector3D &a, const Vector3D &b)
Inequality operator.
Definition vector.cc:174
Vector3DValue VectorValue
Vector alias typedef for compatibility with mobility models.
Definition vector.h:385
friend Vector3D operator+(const Vector3D &a, const Vector3D &b)
Addition operator.
Definition vector.cc:180
friend Vector3D operator*(const Vector3D &a, double b)
Scalar multiplication operator.
Definition vector.cc:192
double x
x coordinate of vector
Definition vector.h:48
friend bool operator==(const Vector3D &a, const Vector3D &b)
Equality operator.
Definition vector.cc:168
friend std::istream & operator>>(std::istream &is, Vector3D &vector)
Input streamer.
Definition vector.cc:131
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition vector.h:378
friend Vector3D operator-(const Vector3D &a, const Vector3D &b)
Subtraction operator.
Definition vector.cc:186
friend bool operator>(const Vector3D &a, const Vector3D &b)
Greater than comparison operator.
Definition vector.cc:156
friend Vector3D CrossProduct(const Vector3D &a, const Vector3D &b)
Cross product.
Definition vector.cc:210
Vector3DChecker VectorChecker
Vector alias typedef for compatibility with mobility models.
Definition vector.h:392
Vector3D()
Create vector (0.0, 0.0, 0.0).
Definition vector.cc:45
double z
z coordinate of vector
Definition vector.h:50
friend bool operator<=(const Vector3D &a, const Vector3D &b)
Less than or equal to comparison operator.
Definition vector.cc:150
double y
y coordinate of vector
Definition vector.h:49
double GetLengthSquared() const
Compute the squared length of the vector.
Definition vector.cc:82
friend bool operator<(const Vector3D &a, const Vector3D &b)
Less than comparison operator.
Definition vector.cc:144
friend double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Calculate the squared Cartesian distance between two points.
Definition vector.cc:110
STL class.
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Ptr< const AttributeChecker > MakeVectorChecker()
Definition vector.cc:31
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:174
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition vector.cc:96
double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Definition vector.cc:110