vector-extensions.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 INESC TEC
4  * Copyright (c) 2021 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Code from https://gitlab.inesctec.pt/pmms/ns3-satellite
20  *
21  * Author: Pedro Silva <pmms@inesctec.pt>
22  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
23  */
24 
25 #include "vector-extensions.h"
26 
27 #include <cmath>
28 
29 namespace ns3
30 {
31 
32 Vector3D
33 operator+(const Vector3D& v1, const Vector3D& v2)
34 {
35  return Vector3D(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
36 }
37 
38 Vector3D
39 operator-(const Vector3D& v1, const Vector3D& v2)
40 {
41  return Vector3D(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
42 }
43 
44 Vector3D
45 operator*(const Vector3D& vector, double scalar)
46 {
47  return Vector3D(vector.x * scalar, vector.y * scalar, vector.z * scalar);
48 }
49 
50 Vector3D
51 operator*(double scalar, const Vector3D& vector)
52 {
53  return vector * scalar;
54 }
55 
56 Vector3D
57 CrossProduct(const Vector3D& v1, const Vector3D& v2)
58 {
59  return Vector3D(v1.y * v2.z - v1.z * v2.y,
60  v1.z * v2.x - v1.x * v2.z,
61  v1.x * v2.y - v1.y * v2.x);
62 }
63 
64 double
65 DotProduct(const Vector3D& v1, const Vector3D& v2)
66 {
67  return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
68 }
69 
70 double
71 Magnitude(const Vector3D& vector)
72 {
73  return std::sqrt(DotProduct(vector, vector));
74 }
75 
76 double
77 MagnitudeSquared(const Vector3D& vector)
78 {
79  return DotProduct(vector, vector);
80 }
81 
82 } // namespace ns3
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Vector3D operator*(const Vector3D &vector, double scalar)
Multiplication between a Vector3D object and a scalar.
double Magnitude(const Vector3D &vector)
Magnitude of a Vector3D object.
double DotProduct(const Vector3D &v1, const Vector3D &v2)
Dot product of two Vector3D objects.
Vector3D operator-(const Vector3D &v1, const Vector3D &v2)
Subtraction of Vector3D objects.
Vector3D operator+(const Vector3D &v1, const Vector3D &v2)
extensions to ns3::Vector3D to support additional operations
double MagnitudeSquared(const Vector3D &vector)
The square of the magnitude of a Vector3D object.
Vector3D CrossProduct(const Vector3D &v1, const Vector3D &v2)
Cross product of two Vector3D objects.