]> git.tdb.fi Git - libs/math.git/blobdiff - source/linal/vector3.h
Rename the library to mspmath and make linal a sublibrary
[libs/math.git] / source / linal / vector3.h
diff --git a/source/linal/vector3.h b/source/linal/vector3.h
new file mode 100644 (file)
index 0000000..90a5ff5
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef MSP_LINAL_VECTOR3_H_
+#define MSP_LINAL_VECTOR3_H_
+
+#include "vector.h"
+
+namespace Msp {
+namespace LinAl {
+
+/**
+A three-dimensional vector, applicable for Euclidean space.
+*/
+template<typename T>
+class Vector3: public Vector<T, 3>
+{
+public:
+       Vector3() { }
+       Vector3(const T *);
+       Vector3(T, T, T);
+       template<typename U>
+       Vector3(const Vector<U, 3> &);
+};
+
+template<typename T>
+inline Vector3<T>::Vector3(const T *d):
+       Vector<T, 3>(d)
+{ }
+
+template<typename T>
+inline Vector3<T>::Vector3(T x, T y, T z)
+{
+       this->data[0] = x;
+       this->data[1] = y;
+       this->data[2] = z;
+}
+
+template<typename T>
+template<typename U>
+inline Vector3<T>::Vector3(const Vector<U, 3> &v):
+       Vector<T, 3>(v)
+{ }
+
+template<typename T>
+inline T dot(const Vector3<T> &v1, const Vector3<T> &v2)
+{
+       return inner_product(v1, v2);
+}
+
+template<typename T>
+inline Vector3<T> cross(const Vector3<T> &v1, const Vector3<T> &v2)
+{
+       return Vector3<T>(v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1]-v1[1]*v2[0]);
+}
+
+} // namespace LinAl
+} // namespace LinAl
+
+#endif