-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec.cpp
More file actions
52 lines (44 loc) · 1.13 KB
/
Copy pathvec.cpp
File metadata and controls
52 lines (44 loc) · 1.13 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
//vec.cpp - Vector library.
//Copyright (c) 2015-2018 Julie VK3FOWL and Joe VK3YSP
//For more information please visit http://www.sarcnet.org
//Released under the GNU General Public License.
//Provides vector functions using cartesian coordinates
#include "vec.h"
#include <Arduino.h>
//Public methods
Vec::Vec() {
//Constructor
i = 0;
j = 0;
k = 0;
}
Vec::Vec(float I, float J, float K) {
//Constructor
i = I;
j = J;
k = K;
}
Vec Vec::cross(const Vec &b) const {
//Returns the vector cross product of two vectors.
return Vec(j * b.k - k * b.j, k * b.i - i * b.k, i * b.j - j * b.i);
}
float Vec::dot(const Vec &b) const {
//Returns the scalar dot product of two vectors.
return i * b.i + j * b.j + k * b.k;
}
float Vec::mod() const {
//Returns the scalar modulus of a vector.
return sqrt(i * i + j * j + k * k);
}
Vec Vec::unit() const {
//Returns the unit vector of a vector.
float modulus = mod();
if (modulus <= 0.000001f) {
return Vec(0, 0, 0);
}
return Vec(i / modulus, j / modulus, k / modulus);
}
Vec Vec::neg() const {
//Returns the vector negative of a vector.
return Vec( -i, -j, -k);
}