35 #ifndef _BLAZE_MATH_QUATERNION_H_
36 #define _BLAZE_MATH_QUATERNION_H_
102 template<
typename Type >
115 explicit inline Quaternion( Type r, Type i, Type j, Type k );
117 template<
typename Axis >
120 explicit inline Quaternion( Type xangle, Type yangle, Type zangle );
122 template<
typename Other >
127 template<
typename Other >
150 inline Type
length()
const;
155 inline void rotateX( Type angle );
156 inline void rotateY( Type angle );
157 inline void rotateZ( Type angle );
165 template<
typename Other,
bool TF >
169 template<
typename Other >
173 template<
typename Other >
177 template<
typename Other >
223 template<
typename Type >
242 template<
typename Type >
245 v_[0] = r; v_[1] = i; v_[2] = j; v_[3] = k;
264 template<
typename Type >
265 template<
typename Axis >
277 const Type sina( std::sin( angle*Type(0.5) ) );
278 const Type cosa( std::cos( angle*Type(0.5) ) );
283 v_[1] = sina * axis[0];
284 v_[2] = sina * axis[1];
285 v_[3] = sina * axis[2];
300 template<
typename Type >
319 template<
typename Type >
320 template<
typename Other >
338 template<
typename Type >
354 template<
typename Type >
355 template<
typename Other >
382 template<
typename Type >
404 template<
typename Type >
405 template<
typename Other >
429 template<
typename Type >
454 template<
typename Type >
479 template<
typename Type >
483 v_[1] = v_[2] = v_[3] = Type(0);
493 template<
typename Type >
498 return std::sqrt( v_[0]*v_[0] + v_[1]*v_[1] + v_[2]*v_[2] + v_[3]*v_[3] );
508 template<
typename Type >
511 const Type len( std::sqrt( v_[0]*v_[0] + v_[1]*v_[1] + v_[2]*v_[2] + v_[3]*v_[3] ) );
516 const Type ilen( Type(1)/len );
533 template<
typename Type >
536 const Type len( std::sqrt( v_[0]*v_[0] + v_[1]*v_[1] + v_[2]*v_[2] + v_[3]*v_[3] ) );
541 const Type ilen( Type(1)/len );
543 return Quaternion( ilen*v_[0], ilen*v_[1], ilen*v_[2], ilen*v_[3] );
553 template<
typename Type >
569 template<
typename Type >
573 Type(2)*( v_[1]*v_[2] - v_[0]*v_[3] ),
574 Type(2)*( v_[1]*v_[3] + v_[0]*v_[2] ),
575 Type(2)*( v_[1]*v_[2] + v_[0]*v_[3] ),
576 Type(1) - Type(2)*v_[1]*v_[1] - Type(2)*v_[3]*v_[3],
577 Type(2)*( v_[2]*v_[3] - v_[0]*v_[1] ),
578 Type(2)*( v_[1]*v_[3] - v_[0]*v_[2] ),
579 Type(2)*( v_[2]*v_[3] + v_[0]*v_[1] ),
580 Type(1) - Type(2)*v_[1]*v_[1] - Type(2)*v_[2]*v_[2] );
591 template<
typename Type >
594 const Type sina( std::sin( angle*Type(0.5) ) );
595 const Type cosa( std::cos( angle*Type(0.5) ) );
598 cosa*v_[1] + sina*v_[0],
599 cosa*v_[2] - sina*v_[3],
600 cosa*v_[3] + sina*v_[2] );
602 this->operator=( q );
613 template<
typename Type >
616 const Type sina( std::sin( angle*Type(0.5) ) );
617 const Type cosa( std::cos( angle*Type(0.5) ) );
620 cosa*v_[1] + sina*v_[3],
621 cosa*v_[2] + sina*v_[0],
622 cosa*v_[3] - sina*v_[1] );
624 this->operator=( q );
635 template<
typename Type >
638 const Type sina( std::sin( angle*Type(0.5) ) );
639 const Type cosa( std::cos( angle*Type(0.5) ) );
642 cosa*v_[1] - sina*v_[2],
643 cosa*v_[2] + sina*v_[1],
644 cosa*v_[3] + sina*v_[0] );
646 this->operator=( q );
658 template<
typename Type >
687 template<
typename Type >
688 template<
typename Other
696 const MT w( v_[1]*v[0] + v_[2]*v[1] + v_[3]*v[2] );
697 const MT x( v_[0]*v[0] - v_[3]*v[1] + v_[2]*v[2] );
698 const MT y( v_[0]*v[1] - v_[1]*v[2] + v_[3]*v[0] );
699 const MT z( v_[0]*v[2] - v_[2]*v[0] + v_[1]*v[1] );
702 v_[0]*y + v_[2]*w + v_[3]*x - v_[1]*z,
703 v_[0]*z + v_[3]*w + v_[1]*y - v_[2]*x );
730 template<
typename Type >
731 template<
typename Other >
754 template<
typename Type >
755 template<
typename Other >
772 template<
typename Type >
773 template<
typename Other >
780 const High y ( u.length() );
781 const High x ( v_[0] );
782 const High dot( u * axis );
784 return High(2) * std::atan2( y, ( dot <
real(0) )?( -x ):( x ) );
800 template<
typename T1,
typename T2 >
803 template<
typename T1,
typename T2 >
806 template<
typename Type >
807 std::ostream& operator<<( std::ostream& os, const Quaternion<Type>& q );
809 template<
typename Type >
812 template<
typename Type >
815 template<
typename Type >
818 template<
typename Type >
821 template<
typename Type >
824 template<
typename Type >
827 template<
typename Type >
830 template<
typename Type >
844 template<
typename T1
850 if( !
equal( lhs[0], rhs[0] ) ||
851 !
equal( lhs[1], rhs[1] ) ||
852 !
equal( lhs[2], rhs[2] ) ||
853 !
equal( lhs[2], rhs[2] ) )
868 template<
typename T1
872 return !( lhs == rhs );
885 template<
typename Type >
886 std::ostream& operator<<( std::ostream& os, const Quaternion<Type>& q )
888 return os <<
"<" << q[0] <<
"," << q[1] <<
"," << q[2] <<
"," << q[3] <<
">";
901 template<
typename Type >
906 char bracket1, bracket2, comma1, comma2, comma3;
907 Type r(0), i(0), j(0), k(0);
908 const std::istream::pos_type pos( is.tellg() );
909 const std::istream::fmtflags oldFlags( is.flags() );
915 if( !(is >> bracket1 >> r >> comma1 >> i >> comma2 >> j >> comma3 >> k >> bracket2) ||
916 bracket1 !=
'<' || comma1 !=
',' || comma2 !=
',' || comma3 !=
',' || bracket2 !=
'>' ) {
919 is.setstate( std::istream::failbit );
920 is.flags( oldFlags );
928 is.flags( oldFlags );
942 template<
typename Type >
959 template<
typename Type >
976 template<
typename Type >
998 template<
typename Type >
1001 return ( q[0] == Type(1) ) && ( q[1] == Type(0) ) && ( q[2] == Type(0) ) && ( q[3] == Type(0) );
1015 template<
typename Type >
1033 template<
typename Type >
1050 template<
typename Type >
1069 template<
typename T1,
typename T2 >
1070 inline const Quaternion< typename MultTrait<T1,T2>::Type >
1071 operator*(
const Quaternion<T1>& lhs,
const Quaternion<T2>& rhs );
1085 template<
typename T1
1087 inline const Quaternion< typename MultTrait<T1,T2>::Type >
1092 const MT r( lhs[0]*rhs[0] - lhs[1]*rhs[1] - lhs[2]*rhs[2] - lhs[3]*rhs[3] );
1093 const MT i( lhs[0]*rhs[1] + lhs[1]*rhs[0] + lhs[2]*rhs[3] - lhs[3]*rhs[2] );
1094 const MT j( lhs[0]*rhs[2] + lhs[2]*rhs[0] + lhs[3]*rhs[1] - lhs[1]*rhs[3] );
1095 const MT k( lhs[0]*rhs[3] + lhs[3]*rhs[0] + lhs[1]*rhs[2] - lhs[2]*rhs[1] );
1097 const MT len2( r*r + i*i + j*j + k*k );
1099 if(
std::fabs( len2 - MT(1) ) < MT(1E-8) ) {
1103 const MT ilen( MT(1) / std::sqrt( len2 ) );
1120 template<
typename T1,
typename T2 >
1121 struct MultTrait< Quaternion<T1>, Quaternion<T2> >
1123 typedef Quaternion< typename MultTrait<T1,T2>::Type > MultType;
1139 template<
typename T1,
typename T2 >
1140 struct MathTrait< Quaternion<T1>, Quaternion<T2> >
1142 typedef Quaternion< typename MathTrait<T1,T2>::HighType > HighType;
1143 typedef Quaternion< typename MathTrait<T1,T2>::LowType > LowType;
Header file for the isnan shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
Quaternion & normalize()
Normalization of the quaternion ( ).
Definition: Quaternion.h:509
Computation accuracy for floating point data types.
const StaticVector< typename MultTrait< Type, Other >::Type, 3UL, false > rotate(const StaticVector< Other, 3UL, TF > &v) const
Rotation of a vector v ( ).
Definition: Quaternion.h:691
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:4329
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
Efficient, generic implementation of a 3x3 rotation matrix.The RotationMatrix class is the representa...
Definition: Forward.h:57
const Quaternion< Type > sq(const Quaternion< Type > &m)
Squaring the given quaternion.
Definition: Quaternion.h:1034
Type v_[4]
The four statically allocated quaternion elements.
Definition: Quaternion.h:187
Type length() const
Calculation of the quaternion length .
Definition: Quaternion.h:494
Type ElementType
Type of the quaternion elements.
Definition: Quaternion.h:107
const StaticMatrix< typename MultTrait< Type, Other >::Type, 3UL, 3UL, false > diagRotate(const StaticMatrix< Other, 3UL, 3UL, false > &m) const
Rotation of a diagonal matrix M ( ).
Definition: RotationMatrix.h:808
const RotationMatrix< Type > toRotationMatrix() const
Conversion to a rotation matrix.
Definition: Quaternion.h:570
const StaticMatrix< Type, 3UL, 3UL, false > fabs(const RotationMatrix< Type > &m)
Returns a matrix containing the absolute values of each single element of m.
Definition: RotationMatrix.h:1102
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
bool isnan(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for not-a-number elements.
Definition: DenseMatrix.h:640
void reset()
Reset to the default initial values.
Definition: Quaternion.h:480
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
Base template for the MathTrait class.
Definition: MathTrait.h:127
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:52
void swap(Quaternion &q)
Swapping the contents of two quaternions.
Definition: Quaternion.h:659
Header file for the floating point precision of the Blaze library.
Header file for the multiplication trait.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4605
Header file for all forward declarations of the math module.
std::istream & operator>>(std::istream &is, Quaternion< Type > &q)
Global input operator for quaternions.
Definition: Quaternion.h:902
Efficient implementation of a fixed-sized matrix.The StaticMatrix class template is the representatio...
Definition: Forward.h:51
Quaternion & set(Type r, Type i, Type j, Type k)
Setting the value of the quaternion elements.
Definition: Quaternion.h:455
Constraint on the data type.
const Quaternion getNormalized() const
Calculation of the normalized quaternion ( ).
Definition: Quaternion.h:534
void rotateY(Type angle)
Rotating the quaternion around the global y-axis by angle degrees (radian measure).
Definition: Quaternion.h:614
MathTrait< Type, Other >::HighType calcAngle(const StaticVector< Other, 3UL, false > &axis) const
Returns the angle in radian measure between the quaterion and a given axis.
Definition: Quaternion.h:775
Quaternion & invert()
Inversion of the quaternion ( ).
Definition: Quaternion.h:554
Header file for the equal shim.
Type operator[](size_t index) const
Subscript operator for the direct access to the quaternion elements.
Definition: Quaternion.h:430
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:352
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4671
Constraint on the data type.
Efficient implementation of a quaternion.Quaternions are a superior way to deal with rotations and or...
Definition: Forward.h:56
Constraint on the data type.
Header file for the isDefault shim.
Quaternion< real > Quat
Quaternion of real type.
Definition: Quaternion.h:1161
double real
Floating point data type of the Blaze library.This type definition offers the possibility to switch t...
Definition: Precision.h:47
Header file for the mathematical trait.
void rotateZ(Type angle)
Rotating the quaternion around the global z-axis by angle degrees (radian measure).
Definition: Quaternion.h:636
const Accuracy accuracy
Global Accuracy instance.The blaze::accuracy instance can be used wherever a floating point data type...
Definition: Accuracy.h:901
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
void rotateX(Type angle)
Rotating the quaternion around the global x-axis by angle degrees (radian measure).
Definition: Quaternion.h:592
Quaternion()
The default constructor for Quaternion.
Definition: Quaternion.h:224
const StaticMatrix< typename MultTrait< Type, Other >::Type, 3UL, 3UL, false > rotate(const StaticMatrix< Other, 3UL, 3UL, false > &m) const
Rotation of a matrix M ( ).
Definition: RotationMatrix.h:744
#define BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.In case the given data type T is not a floating point data type...
Definition: FloatingPoint.h:79
const StaticMatrix< typename MultTrait< Type, Other >::Type, 3UL, 3UL, false > diagRotate(const StaticMatrix< Other, 3UL, 3UL, false > &m) const
Rotation of a diagonal matrix.
Definition: Quaternion.h:757
const Quaternion< Type > inv(const Quaternion< Type > &m)
Inverting the given quaternion ( ).
Definition: Quaternion.h:1016