Loading...
Searching...
No Matches
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
30namespace ns3
31{
32
33Vector3D
34operator+(const Vector3D& v1, const Vector3D& v2)
35{
36 return Vector3D(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
37}
38
39Vector3D
40operator-(const Vector3D& v1, const Vector3D& v2)
41{
42 return Vector3D(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
43}
44
45Vector3D
46operator*(const Vector3D& vector, double scalar)
47{
48 return Vector3D(vector.x * scalar, vector.y * scalar, vector.z * scalar);
49}
50
51Vector3D
52operator*(double scalar, const Vector3D& vector)
53{
54 return vector * scalar;
55}
56
57Vector3D
58CrossProduct(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
65double
66DotProduct(const Vector3D& v1, const Vector3D& v2)
67{
68 return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
69}
70
71double
72Magnitude(const Vector3D& vector)
73{
74 return std::sqrt(DotProduct(vector, vector));
75}
76
77double
78MagnitudeSquared(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.