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 #include <stdint.h>
29 
30 namespace ns3
31 {
32 
33 Vector3D
34 operator+(const Vector3D& v1, const Vector3D& v2)
35 {
36  return Vector3D(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
37 }
38 
39 Vector3D
40 operator-(const Vector3D& v1, const Vector3D& v2)
41 {
42  return Vector3D(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
43 }
44 
45 Vector3D
46 operator*(const Vector3D& vector, double scalar)
47 {
48  return Vector3D(vector.x * scalar, vector.y * scalar, vector.z * scalar);
49 }
50 
51 Vector3D
52 operator*(double scalar, const Vector3D& vector)
53 {
54  return vector * scalar;
55 }
56 
57 Vector3D
58 CrossProduct(const Vector3D& v1, const Vector3D& v2)
59 {
60  return Vector3D(v1.y * v2.z - v1.z * v2.y,
61  v1.z * v2.x - v1.x * v2.z,
62  v1.x * v2.y - v1.y * v2.x);
63 }
64 
65 double
66 DotProduct(const Vector3D& v1, const Vector3D& v2)
67 {
68  return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
69 }
70 
71 double
72 Magnitude(const Vector3D& vector)
73 {
74  return std::sqrt(DotProduct(vector, vector));
75 }
76 
77 double
78 MagnitudeSquared(const Vector3D& vector)
79 {
80  return DotProduct(vector, vector);
81 }
82 
83 } // 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.