-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVector_math.h
More file actions
63 lines (53 loc) · 1.54 KB
/
Copy pathVector_math.h
File metadata and controls
63 lines (53 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
#ifndef INCLUDED_MATH_VECTORMATH
#define INCLUDED_MATH_VECTORMATH
#include "Vector.h"
#include "Unit_vector.h"
#include "Point.h"
namespace Dubious {
namespace Math {
template <int T>
VectorT<T>
cross_product(const VectorT<T>& a, const VectorT<T>& b)
{
return VectorT<T>((a.y() * b.z()) - (a.z() * b.y()), (a.z() * b.x()) - (a.x() * b.z()),
(a.x() * b.y()) - (a.y() * b.x()));
}
template <int T>
VectorT<T>
cross_product(const Unit_vectorT<T>& a, const Unit_vectorT<T>& b)
{
return VectorT<T>((a.y() * b.z()) - (a.z() * b.y()), (a.z() * b.x()) - (a.x() * b.z()),
(a.x() * b.y()) - (a.y() * b.x()));
}
template <int T>
float
dot_product(const VectorT<T>& a, const VectorT<T>& b)
{
return a.x() * b.x() + a.y() * b.y() + a.z() * b.z();
}
template <int T>
float
dot_product(const Unit_vectorT<T>& a, const Unit_vectorT<T>& b)
{
return a.x() * b.x() + a.y() * b.y() + a.z() * b.z();
}
// As much as I'd like to enforce that points and vectors are
// unique things that can't be arbitrarily converted, there
// do exists realities when points just need to be vectors.
// At least using a specific function will let me search for
// this if I come up with something cleaner in the future.
template <int T>
VectorT<T>
to_vector(const PointT<T>& p)
{
return VectorT<T>(p.x(), p.y(), p.z());
}
template <int T>
PointT<T>
to_point(const VectorT<T>& v)
{
return PointT<T>(v.x(), v.y(), v.z());
}
} // namespace Math
} // namespace Dubious
#endif