]> git.tdb.fi Git - libs/math.git/blob - source/linal/vector3.h
Some basic test cases
[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 *d): Vector<T, 3>(d) { }
18         Vector3(T, T, T);
19         template<typename U>
20         Vector3(const Vector<U, 3> &v): Vector<T, 3>(v) { }
21 };
22
23 template<typename T>
24 inline Vector3<T>::Vector3(T x, T y, T z)
25 {
26         this->data[0] = x;
27         this->data[1] = y;
28         this->data[2] = z;
29 }
30
31 template<typename T>
32 inline T dot(const Vector<T, 3> &v1, const Vector<T, 3> &v2)
33 {
34         return inner_product(v1, v2);
35 }
36
37 template<typename T>
38 inline Vector<T, 3> cross(const Vector<T, 3> &v1, const Vector<T, 3> &v2)
39 {
40         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]);
41 }
42
43 } // namespace LinAl
44 } // namespace Msp
45
46 #endif