-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3DMath.cpp
More file actions
64 lines (41 loc) · 1.5 KB
/
Copy pathVector3DMath.cpp
File metadata and controls
64 lines (41 loc) · 1.5 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
#pragma once
#include <vector>
#include <array>
#include <cmath>
namespace Vector3DMath
{
std::array<float,3> substract(const std::array<float, 3> op1, const std::array<float, 3> op2){
std::array<float,3> result;
result[0] = op1[0] - op2[0];
result[1] = op1[1] - op2[1];
result[2] = op1[2] - op2[2];
return result;
}
std::array<float,3> scalar(const std::array<float, 3> op, const float scalar){
std::array<float,3> result;
result[0] = op[0] * scalar;
result[1] = op[1] * scalar;
result[2] = op[2] * scalar;
return result;
}
float getLength(const std::array<float, 3> op){
return std::sqrt(std::pow(op[0],2.0f) + std::pow(op[1],2.0f) + std::pow(op[2],2.0f));
}
std::array<float,3> normalize(const std::array<float, 3> op){
std::array<float,3> result;
float lenght = getLength(op);
result[0] = op[0] / lenght;
result[1] = op[1] / lenght;
result[2] = op[2] / lenght;
return result;
}
float multiply(const std::array<float, 3> p1, const std::array<float, 3> p2){
return p1[0] * p2[0] + p1[1] * p2[1] + p1[2] * p2[2];
}
float angleCosine(const std::array<float, 3> op1,const std::array<float, 3> op2){
return multiply(op1,op2) / (getLength(op1) * getLength(op2));
}
float dot(const std::array<float, 3> p1, const std::array<float, 3> p2){
return multiply(p1,p2);
}
}