]> git.tdb.fi Git - libs/math.git/blob - source/linal/vector3.h
Another big batch of stuff
[libs/math.git] / source / linal / vector3.h
1 #ifndef MSP_LINAL_VECTOR3_H_
2 #define MSP_LINAL_VECTOR3_H_
3
4 #include "vector.h"
5
6 namespace Msp {
7 namespace LinAl {
8
9 /**
10 A three-dimensional vector, applicable for Euclidean space.
11 */
12 template<typename T>
13 class Vector3: public Vector<T, 3>
14 {
15 public:
16         Vector3() { }
17         Vector3(const T *);
18         Vector3(T, T, T);
19         template<typename U>
20         Vector3(const Vector<U, 3> &);
21 };
22
23 template<typename T>
24 inline Vector3<T>::Vector3(const T *d):
25         Vector<T, 3>(d)
26 { }
27
28 template<typename T>
29 inline Vector3<T>::Vector3(T x, T y, T z)
30 {
31         this->data[0] = x;
32         this->data[1] = y;
33         this->data[2] = z;
34 }
35
36 template<typename T>
37 template<typename U>
38 inline Vector3<T>::Vector3(const Vector<U, 3> &v):
39         Vector<T, 3>(v)
40 { }
41
42 template<typename T>
43 inline T dot(const Vector<T, 3> &v1, const Vector<T, 3> &v2)
44 {
45         return inner_product(v1, v2);
46 }
47
48 template<typename T>
49 inline Vector<T, 3> cross(const Vector<T, 3> &v1, const Vector<T, 3> &v2)
50 {
51         return Vector<T, 3>(v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1]-v1[1]*v2[0]);
52 }
53
54 } // namespace LinAl
55 } // namespace Msp
56
57 #endif