Go to the documentation of this file. 1 #ifndef __GfxTL_VECTORXD_HEADER__
2 #define __GfxTL_VECTORXD_HEADER__
4 #ifndef _USE_MATH_DEFINES
5 #define _USE_MATH_DEFINES
19 template <
unsigned int D,
class T>
20 class VectorXD :
public MatrixXX<1, D, T>
43 memcpy(SuperType::_m,
v,
sizeof(SuperType::_m));
49 for (
unsigned int i = 0; i <
Dim; ++i)
51 SuperType::_m[i] = (
T)
v[i];
58 for (
unsigned int i = 0; i <
Dim; ++i)
60 SuperType::_m[i] = (
T)
v[i];
70 for (
unsigned int i = 0; i <
Dim; ++i)
81 for (
unsigned int i = 0; i <
Dim; ++i)
87 template <
unsigned int X>
90 for (
unsigned int i = 0; i <
std::min(D, X); ++i)
92 SuperType::_m[i] = vec[i];
94 for (
unsigned int i = X; i < D; ++i)
102 for (
unsigned int i = 0; i < D - 1; ++i)
104 SuperType::_m[i] =
v[i];
106 SuperType::_m[D - 1] =
s;
111 for (
unsigned int i = 0; i < D - 2; ++i)
113 SuperType::_m[i] =
v[i];
115 SuperType::_m[D - 2] =
s;
116 SuperType::_m[D - 1] = s2;
121 for (
unsigned int i = 0; i < D - 2; ++i)
123 SuperType::_m[i] =
v[i];
125 SuperType::_m[D - 3] =
s;
126 SuperType::_m[D - 2] = s2;
127 SuperType::_m[D - 1] = s3;
135 SuperType::_m[0] = x;
136 SuperType::_m[1] = y;
144 SuperType::_m[0] = x;
145 SuperType::_m[1] = y;
146 SuperType::_m[2] = z;
154 SuperType::_m[0] = x;
155 SuperType::_m[1] = y;
156 SuperType::_m[2] = z;
157 SuperType::_m[3] = w;
176 for (
unsigned int i = 0; i < D; ++i)
178 SuperType::_m[i] = (
T)
v[0][i];
186 return SuperType::_m[i];
192 return SuperType::_m[i];
208 for (
unsigned int i = 0; i < D; ++i)
210 SuperType::_m[i] +=
a.Data()[i];
218 for (
unsigned int i = 0; i < D; ++i)
220 SuperType::_m[i] -=
a.Data()[i];
229 for (
unsigned int i = 0; i < D; ++i)
231 SuperType::_m[i] *=
s;
240 for (
unsigned int i = 0; i < D; ++i)
242 SuperType::_m[i] /=
s;
263 for (
unsigned int i = 0; i < D; ++i)
265 s += SuperType::_m[i] * SuperType::_m[i];
274 for (
unsigned int i = 0; i < D; ++i)
276 s +=
abs(SuperType::_m[i]);
284 memset(SuperType::_m, 0,
sizeof(SuperType::_m));
290 return memcmp(SuperType::_m,
a._m,
sizeof(SuperType::_m)) == 0;
297 diff = SuperType::_m[0] -
v[0];
299 for (
unsigned int i = 1; i <
Dim; ++i)
301 diff = SuperType::_m[i] -
v[i];
317 for (
unsigned int i = 1; i <
Dim; ++i)
328 for (
unsigned int i = 1; i <
Dim; ++i)
343 for (
unsigned int i = 0; i <
Dim; ++i)
345 p[i] = SuperType::_m[i];
357 return SuperType::_m;
363 return SuperType::_m + D;
369 return SuperType::_m;
375 return SuperType::_m + D;
379 template <
unsigned int D,
class T>
384 for (
unsigned int i = 0; i < D; ++i)
396 template <
unsigned int D,
class T>
397 inline const VectorXD<D, T>
401 for (
unsigned int i = 0; i < D; ++i)
409 inline const VectorXD<1, T>
416 inline const VectorXD<2, T>
423 inline const VectorXD<3, T>
430 inline const VectorXD<4, T>
436 template <
unsigned int D,
class T>
437 inline const VectorXD<D, T>
441 for (
unsigned int i = 0; i < D; ++i)
449 inline const VectorXD<1, T>
456 inline const VectorXD<2, T>
463 inline const VectorXD<3, T>
470 inline const VectorXD<4, T>
477 template <
unsigned int D,
class T>
482 for (
unsigned int i = 1; i < D; ++i)
484 retVal +=
a[i] * b[i];
490 template <
unsigned int A,
unsigned int B,
class T>
491 inline MatrixXX<B, A, T>
495 for (
unsigned int c = 0;
c < B; ++
c)
496 for (
unsigned int r = 0; r <
A; ++r)
498 m[
c][r] =
a[r] * b[
c];
503 template <
unsigned int D,
class T>
504 inline MatrixXX<D, D, T>
508 for (
unsigned int c = 0;
c < D; ++
c)
511 for (
unsigned int r =
c + 1; r < D; ++r)
513 m[
c][r] =
a[r] *
a[
c];
531 return a[0] * b[0] +
a[1] * b[1];
538 return a[0] * b[0] +
a[1] * b[1] +
a[2] * b[2];
545 return a[0] * b[0] +
a[1] * b[1] +
a[2] * b[2] +
a[3] * b[3];
548 template <
unsigned int D,
class T>
549 inline VectorXD<D, T>
553 for (
unsigned int i = 0; i < D; ++i)
561 inline const VectorXD<1, T>
568 inline const VectorXD<2, T>
575 inline const VectorXD<3, T>
582 inline const VectorXD<4, T>
588 template <
unsigned int D,
class T>
589 inline VectorXD<D, T>
593 for (
unsigned int i = 0; i < D; ++i)
601 inline const VectorXD<1, T>
608 inline const VectorXD<2, T>
615 inline const VectorXD<3, T>
622 inline const VectorXD<4, T>
628 template <
unsigned int D,
class T>
629 inline VectorXD<D, T>
633 for (
unsigned int i = 0; i < D; ++i)
641 inline const VectorXD<1, T>
648 inline const VectorXD<2, T>
655 inline const VectorXD<3, T>
662 inline const VectorXD<4, T>
669 inline const VectorXD<3, T>
673 a[1] * b[2] - b[1] *
a[2],
a[2] * b[0] -
a[0] * b[2],
a[0] * b[1] -
a[1] * b[0]);
676 template <
unsigned int D,
class T>
677 inline VectorXD<D, T>
682 for (
unsigned int r = 0; r < D; ++r)
684 m[r] =
min(
a[r], b[r]);
689 template <
unsigned int D,
class T>
690 inline VectorXD<D, T>
695 for (
unsigned int r = 0; r < D; ++r)
697 m[r] =
max(
a[r], b[r]);
702 template <
unsigned int D,
class T>
703 inline VectorXD<D, T>
707 for (
unsigned int i = 0; i < D; ++i)
774 T rad = (deg * (
T)
M_PI / (
T)180.0) / (
T)2.0;
775 (*this)[0] = std::cos(rad);
786 (*this)[0] = std::cos(rad / 2);
787 T s = std::sin(rad / 2);
804 *deg = ((
T)std::acos((*
this)[0]) * (
T)2.0) * (
T)180.0 / (
T)
M_PI;
805 T sinA = (
T)
std::sqrt(1.0 - (*
this)[0] * (*this)[0]);
806 T absSin = sinA < 0 ? -sinA : sinA;
807 if (absSin < (
T)0.00005)
811 *a0 = (*this)[1] / sinA;
812 *a1 = (*this)[2] / sinA;
813 *a2 = (*this)[3] / sinA;
819 *rad = ((
T)std::acos((*
this)[0]) * (
T)2.0);
820 T sinA = (
T)
std::sqrt(1.0 - (*
this)[0] * (*this)[0]);
821 T absSin = sinA < 0 ? -sinA : sinA;
822 if (absSin < (
T)0.00005)
826 *a0 = (*this)[1] / sinA;
827 *a1 = (*this)[2] / sinA;
828 *a2 = (*this)[3] / sinA;
834 Rotation(deg, &(*axis)[0], &(*axis)[1], &(*axis)[2]);
851 return Quaternion<T>((*
this)[0], -(*
this)[1], -(*
this)[2], -(*
this)[3]);
859 for (
unsigned int i = 0; i < 4; ++i)
875 T xy =
q[1] *
q[2] * 2;
876 T zw =
q[0] *
q[3] * 2;
877 T xz =
q[1] *
q[3] * 2;
878 T xw =
q[1] *
q[0] * 2;
879 T yw =
q[0] *
q[2] * 2;
880 T yz =
q[2] *
q[3] * 2;
882 (*mat)[0][0] = ww + xx - yy - zz;
883 (*mat)[0][1] = xy + zw;
884 (*mat)[0][2] = xz - yw;
886 (*mat)[1][0] = xy - zw;
887 (*mat)[1][1] = ww - xx + yy - zz;
888 (*mat)[1][2] = yz + xw;
890 (*mat)[2][0] = xz + yw;
891 (*mat)[2][1] = yz - xw;
892 (*mat)[2][2] = ww - xx - yy + zz;
913 a[0] * b[1] +
a[1] * b[0] +
a[2] * b[3] -
a[3] * b[2],
914 a[0] * b[2] -
a[1] * b[3] +
a[2] * b[0] +
a[3] * b[1],
915 a[0] * b[3] +
a[1] * b[2] -
a[2] * b[1] +
a[3] * b[0]);
void Rotation(T *deg, VectorXD< 3, T > *axis) const
ThisType & operator=(const SuperType &s)
void Rotation(T *deg, T *a0, T *a1, T *a2) const
VectorXD< 4, float > Vec4f
VectorXD< 3, float > Vec3f
void RotationRad(T *rad, T *a0, T *a1, T *a2) const
void Rotate(const V &p, V *r) const
VectorXD< 3, double > Vec3d
VectorXD< D, T > & operator+=(const MatrixXX< 1, D, T > &a)
VectorXD< 3, float > vec3
VectorXD< 2, float > vec2
VectorXD< 3, float > vec3f
MatrixXX< B, A, T > OuterProduct(const VectorXD< A, T > &a, const VectorXD< B, T > &b)
VectorXD< 4, float > vec4f
MatrixXX< 1, D, T > SuperType
VectorXD< 1, double > Vector1Dd
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
ScalarType SqrLength() const
const ScalarType * end() const
VectorXD(const S x, typename std::enable_if< std::is_convertible< S, ScalarType >::value, NullClass >::type &dummy= *((NullClass *) 0))
const VectorXD< 3, T > operator%(const VectorXD< 3, T > &a, const VectorXD< 3, T > &b)
VectorXD< 2, unsigned int > uvec2
VectorXD< 3, float > Vector3Df
Quaternion< T > Inverse() const
VectorXD< D, T > ThisType
ScalarType operator[](unsigned int i) const
ScalarType Distance(const VectorXD< D, T > &v) const
VectorXD< 1, double > Vec1d
static ScalarT Abs(ScalarT s)
VectorXD(const VectorXD< D - 2, T > &v, T s, T s2)
VectorXD< Dim+1, T > Homogene() const
const typedef ScalarType * const_iterator
ScalarType L1Distance(const VectorXD< D, T > &v) const
VectorXD< 3, unsigned int > uvec3
VectorXD< 4, unsigned int > uvec4
VectorXD< D, T > operator-() const
void Rotation(T deg, T a0, T a1, T a2)
double a(double t, double a0, double j)
std::shared_ptr< Value > value()
std::ostream & operator<<(std::ostream &o, const Array< DimT, IteratorT > &a)
std::vector< T > abs(const std::vector< T > &v)
ScalarType MaxDistance(const VectorXD< D, T > &v) const
MatrixXX< C, R, T > operator-(const MatrixXX< C, R, T > &a)
ThisType & operator=(T v)
const ScalarType * begin() const
VectorXD< D, T > & operator/=(S s)
VectorXD< 2, double > Vector2Dd
VectorXD< 4, double > Vector4Dd
VectorXD< 3, double > Vector3Dd
VectorXD(const SuperType &s)
Quaternion(T w, T x, T y, T z)
void Rotation(T deg, const VectorXD< 3, T > &a)
VectorXD(const VectorXD< D, S > &v)
VectorXD< 4, float > vec4
VectorXD(const VectorXD< D, T > &v)
MatrixXX< C, R, T > min(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
ThisType & operator=(const ThisType &v)
VectorXD< 2, double > Vec2d
class A(deque< T, A >)) ARMARX_OVERLOAD_STD_HASH_FOR_ITERABLE((class T
Enables hashing of std::list.
VectorXD< 1, float > vec1
VectorXD(const VectorXD< D - 1, T > &v, T s)
VectorXD(const VectorXD< X, T > &vec)
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
double v(double t, double v0, double a0, double j)
VectorXD< 1, float > vec1f
void RotationRad(T rad, T a0, T a1, T a2)
VectorXD< 1, float > Vector1Df
static void AssertEqual()
ThisType & operator=(const MatrixXX< 1, D, S > &v)
void RotationMatrix(M *mat)
Quaternion< T > & operator*=(const Quaternion< T > &b)
VectorXD< 1, float > Vec1f
VectorXD< 2, float > Vector2Df
bool operator==(const VectorXD< D, T > &a) const
VectorXD< D, T > & operator*=(S s)
VectorXD< 2, float > Vec2f
VectorXD< 2, float > vec2f
ScalarType L1Length() const
VectorXD< 4, double > Vec4d
ScalarType & operator[](unsigned int i)
Quaternion< T > Conjugate() const
MatrixXX< D, D, T > SqrOuterProduct(const VectorXD< D, T > &a)
VectorXD< 1, unsigned int > uvec1
double s(double t, double s0, double v0, double a0, double j)
VectorXD(const VectorXD< D - 3, T > &v, T s, T s2, T s3)
VectorXD< D, T > & operator-=(const MatrixXX< 1, D, T > &a)
VectorXD< D, T > operator/(const VectorXD< D, T > &a, T s)
ScalarType SqrDistance(const VectorXD< D, T > &v) const
VectorXD(T x, T y, T z, T w)
const MatrixXX< C, R, T > operator+(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
VectorXD< 4, float > Vector4Df
const MatrixXX< C, R, T > operator*(T s, const MatrixXX< C, R, T > &a)
VectorXD< 4, T > SuperType
ScalarType Length() const