forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector3d.cpp
More file actions
73 lines (61 loc) · 1.54 KB
/
Copy pathvector3d.cpp
File metadata and controls
73 lines (61 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// vector3d.cpp
// Class providing common math operations for 3D points
//
// Author: Tilman Schramke, Christoph Dalitz
// Date: 2017-03-16
// License: see LICENSE-BSD2
//
#include "vector3d.h"
#include <math.h>
Vector3d::Vector3d() {
x = 0; y = 0; z = 0;
}
Vector3d::Vector3d(track_t a, track_t b, track_t c) {
x = a; y = b; z = c;
}
bool Vector3d::operator==(const Vector3d &rhs) const {
if((x == rhs.x) && (y == rhs.y) && (z == rhs.z))
return true;
return false;
}
Vector3d& Vector3d::operator=(const Vector3d& other) {
x = other.x; y = other.y; z = other.z;
return *this;
}
// nicely formatted output
std::ostream& operator<<(std::ostream& strm, const Vector3d& vec) {
return strm << "(" << vec.x << ", " << vec.y << ", " << vec.z << ")";
}
// Euclidean norm
track_t Vector3d::norm() const {
return sqrt((x * x) + (y * y) + (z * z));
}
// mathematical vector operations
// vector addition
Vector3d operator+(Vector3d x, Vector3d y) {
Vector3d v(x.x + y.x, x.y + y.y, x.z + y.z);
return v;
}
// vector subtraction
Vector3d operator-(Vector3d x, Vector3d y) {
Vector3d v(x.x - y.x, x.y - y.y, x.z - y.z);
return v;
}
// scalar product
track_t operator*(Vector3d x, Vector3d y) {
return (x.x*y.x + x.y*y.y + x.z*y.z);
}
// scalar multiplication
Vector3d operator*(Vector3d x, track_t c) {
Vector3d v(c*x.x, c*x.y, c*x.z);
return v;
}
Vector3d operator*(track_t c, Vector3d x) {
Vector3d v(c*x.x, c*x.y, c*x.z);
return v;
}
Vector3d operator/(Vector3d x, track_t c) {
Vector3d v(x.x/c, x.y/c, x.z/c);
return v;
}