15 #ifndef INCLUDED_numeric_Quaternion_hh
16 #define INCLUDED_numeric_Quaternion_hh
43 template<
typename T >
98 bool const precise =
true
322 return T( 2 ) * std::acos(
w_ );
352 return (
w_ * q.w_ ) + (
x_ * q.x_ ) + (
y_ * q.y_ ) + (
z_ * q.z_ );
361 return (
w_ * q.w_ ) + (
x_ * q.x_ ) + (
y_ * q.y_ ) + (
z_ * q.z_ );
374 if ( norm_sq !=
T( 1 ) ) {
375 assert( norm_sq >
T( 0 ) );
376 Value const norm_inv(
T( 1 ) / std::sqrt( norm_sq ) );
393 assert( norm_sq >
T( 0 ) );
394 Value const norm_inv(
T( 1 ) / std::sqrt( norm_sq ) );
458 w_ = ( q.w_ * w_o ) - ( q.x_ * x_o ) - ( q.y_ * y_o ) - ( q.z_ *
z_ );
459 x_ = ( q.w_ * x_o ) + ( q.x_ * w_o ) + ( q.y_ *
z_ ) - ( q.z_ * y_o );
460 y_ = ( q.w_ * y_o ) - ( q.x_ *
z_ ) + ( q.y_ * w_o ) + ( q.z_ * x_o );
461 z_ = ( q.w_ *
z_ ) + ( q.x_ * y_o ) - ( q.y_ * x_o ) + ( q.z_ * w_o );
475 w_= ( w_o * q.w_ ) - ( x_o * q.x_ ) - ( y_o * q.y_ ) - (
z_ * q.z_ );
476 x_= ( w_o * q.x_ ) + ( x_o * q.w_ ) + ( y_o * q.z_ ) - (
z_ * q.y_ );
477 y_= ( w_o * q.y_ ) - ( x_o * q.z_ ) + ( y_o * q.w_ ) + (
z_ * q.x_ );
478 z_= ( w_o * q.z_ ) + ( x_o * q.y_ ) - ( y_o * q.x_ ) + (
z_ * q.w_ );
492 w_ = ( q.w_ * w_o ) - ( q.x_ * x_o ) - ( q.y_ * y_o ) - ( q.z_ *
z_ );
493 x_ = ( q.w_ * x_o ) + ( q.x_ * w_o ) + ( q.y_ *
z_ ) - ( q.z_ * y_o );
494 y_ = ( q.w_ * y_o ) - ( q.x_ *
z_ ) + ( q.y_ * w_o ) + ( q.z_ * x_o );
495 z_ = ( q.w_ *
z_ ) + ( q.x_ * y_o ) - ( q.y_ * x_o ) + ( q.z_ * w_o );
509 w_ = ( w_o * q.w_ ) - ( x_o * q.x_ ) - ( y_o * q.y_ ) - (
z_ * q.z_ );
510 x_ = ( w_o * q.x_ ) + ( x_o * q.w_ ) + ( y_o * q.z_ ) - (
z_ * q.y_ );
511 y_ = ( w_o * q.y_ ) - ( x_o * q.z_ ) + ( y_o * q.w_ ) + (
z_ * q.x_ );
512 z_ = ( w_o * q.z_ ) + ( x_o * q.y_ ) - ( y_o * q.x_ ) + (
z_ * q.w_ );
524 t =
w_;
w_ = q.w_; q.w_ = t;
525 t =
x_;
x_ = q.x_; q.x_ = t;
526 t =
y_;
y_ = q.y_; q.y_ = t;
527 t =
z_;
z_ = q.z_; q.z_ = t;
559 ( q2.w_ * q1.w_ ) - ( q2.x_ * q1.x_ ) - ( q2.y_ * q1.y_ ) - ( q2.z_ * q1.z_ ),
560 ( q2.w_ * q1.x_ ) + ( q2.x_ * q1.w_ ) + ( q2.y_ * q1.z_ ) - ( q2.z_ * q1.y_ ),
561 ( q2.w_ * q1.y_ ) - ( q2.x_ * q1.z_ ) + ( q2.y_ * q1.w_ ) + ( q2.z_ * q1.x_ ),
562 ( q2.w_ * q1.z_ ) + ( q2.x_ * q1.y_ ) - ( q2.y_ * q1.x_ ) + ( q2.z_ * q1.w_ )
575 ( q2.w_ * q1.w_ ) - ( q2.x_ * q1.x_ ) - ( q2.y_ * q1.y_ ) - ( q2.z_ * q1.z_ ),
576 ( q2.w_ * q1.x_ ) + ( q2.x_ * q1.w_ ) + ( q2.y_ * q1.z_ ) - ( q2.z_ * q1.y_ ),
577 ( q2.w_ * q1.y_ ) - ( q2.x_ * q1.z_ ) + ( q2.y_ * q1.w_ ) + ( q2.z_ * q1.x_ ),
578 ( q2.w_ * q1.z_ ) + ( q2.x_ * q1.y_ ) - ( q2.y_ * q1.x_ ) + ( q2.z_ * q1.w_ )
582 ( q2.w_ * q1.w_ ) - ( q2.x_ * q1.x_ ) - ( q2.y_ * q1.y_ ) - ( q2.z_ * q1.z_ ),
583 ( q2.w_ * q1.x_ ) + ( q2.x_ * q1.w_ ) + ( q2.y_ * q1.z_ ) - ( q2.z_ * q1.y_ ),
584 ( q2.w_ * q1.y_ ) - ( q2.x_ * q1.z_ ) + ( q2.y_ * q1.w_ ) + ( q2.z_ * q1.x_ ),
585 ( q2.w_ * q1.z_ ) + ( q2.x_ * q1.y_ ) - ( q2.y_ * q1.x_ ) + ( q2.z_ * q1.w_ )
613 return ( ( q1.w_ == q2.w_ ) && ( q1.x_ == q2.x_ ) && ( q1.y_ == q2.y_ ) && ( q1.z_ == q2.z_ ) );
623 return ( ( q1.w_ != q2.w_ ) || ( q1.x_ != q2.x_ ) || ( q1.y_ != q2.y_ ) || ( q1.z_ != q2.z_ ) );
633 return ( q1.w_ * q2.w_ ) + ( q1.x_ * q2.x_ ) + ( q1.y_ * q2.y_ ) + ( q1.z_ * q2.z_ );
643 return ( q1.w_ * q2.w_ ) + ( q1.x_ * q2.x_ ) + ( q1.y_ * q2.y_ ) + ( q1.z_ * q2.z_ );
667 template<
typename T >
673 template<
typename T >
679 template<
typename T >
685 template<
typename T >
691 template<
typename T >
697 template<
typename T >
705 #endif // INCLUDED_numeric_Quaternion_HH
Rigid body 3-D position/transform.
bool operator==(BodyPosition< T > const &p1, BodyPosition< T > const &p2)
BodyPosition == BodyPosition.
NumericTraits< T > Traits
xyzVector & assign(Value const &x_a, Value const &y_a, Value const &z_a)
Triple value assignment.
Value dot_product(Quaternion const &q) const
Dot product.
Quaternion inverse() const
Inverse.
Value magnitude_squared() const
Magnitude squared: Should be one.
Value z_squared() const
z squared
Value norm() const
Norm: Should be one.
Value const & w() const
w
NumericTraits: Numeric type traits.
Value norm_squared_error() const
Norm squared error.
MathMatrix< T > operator*(const MathMatrix< T > &MATRIX_LHS, const MathMatrix< T > &MATRIX_RHS)
multiply two matrixs of equal size by building the inner product yielding the scalar product ...
Quaternion & normalize()
Normalize.
Quaternion & apply(Quaternion const &q, bool const precise=true)
Apply a successive Quaternion.
Quaternion & left_multiply_by(Quaternion const &q, bool const precise=true)
Left multiply by a Quaternion.
numeric::BodyPosition forward declarations
friend Value dot_product(Quaternion const &q1, Quaternion const &q2)
Dot product.
Quaternion(Value const &w_a, Value const &x_a, Value const &y_a, Value const &z_a, bool const precise=true)
Coordinate constructor.
Value norm_error() const
Norm error.
Quaternion & right_multiply_by(Quaternion const &q, bool const precise=true)
Right multiply by a Quaternion.
Quaternion & right_multiply_by_inverse_of(Quaternion const &q, bool const precise=true)
Right multiply by the inverse of a Quaternion.
static Quaternion const & I()
Identity Quaternion for expressions.
Value w_squared() const
w squared
Value norm_squared() const
Norm squared: Should be one.
Axis axis() const
Axis of Rotation unit vector (direction for angle on [0,2*pi])
T const & const_reference
friend Quaternion product(Quaternion const &q2, Quaternion const &q1, bool const precise=true)
Product: Quaternion * Quaternion.
numeric::Quaternion forward declarations
friend bool operator==(Quaternion const &q1, Quaternion const &q2)
Quaternion == Quaternion.
T abs(T const &x)
std::abs( x ) == | x |
Value const & x() const
x
void product(ForwardIterator probs1_first, ForwardIterator probs1_last, ForwardIterator probs2_first, ForwardIterator probs2_last)
Multiplies two probability vectors with one another. Probability vectors are assumed to have equal le...
Value magnitude_squared_error() const
Magnitude squared error.
Value y_squared() const
y squared
Value x_squared() const
x squared
Quaternion & invert()
Invert.
Quaternion conjugated() const
Conjugated.
Quaternion & to_identity()
Identity.
Value magnitude_error() const
Magnitude error.
Quaternion & operator=(Quaternion const &q)
friend Value dot(Quaternion const &q1, Quaternion const &q2)
Dot product.
Value magnitude() const
Magnitude: Should be one.
static Quaternion identity()
Identity named constructor.
Value dot(Quaternion const &q) const
Dot product.
xyzVector & normalize_or_zero()
Normalize: zero xyzVector if length is zero.
bool operator!=(BodyPosition< T > const &p1, BodyPosition< T > const &p2)
BodyPosition != BodyPosition.
T dot_product(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
bool is_normalized(Value const &tol=Traits::quaternion_tolerance()) const
Magnitude squared error within tolerance?
Quaternion & normalize_if_needed(Value const &tol=Traits::quaternion_tolerance())
Normalize if magnitude squared error exceeds tolerance.
friend bool operator!=(Quaternion const &q1, Quaternion const &q2)
Quaternion != Quaternion.
friend Quaternion operator*(Quaternion const &q2, Quaternion const &q1)
Quaternion * Quaternion.
bool not_normalized(Value const &tol=Traits::quaternion_tolerance()) const
Magnitude squared error exceeds tolerance?
Value const & y() const
y
Quaternion(Quaternion const &q)
Copy constructor.
Axis & axis(Axis &u) const
Axis of rotation unit vector: Passed vector (direction for angle on [0,2*pi])
void swap(Quaternion &q)
Swap.
Fast (x,y,z)-coordinate numeric vector.
Value angle() const
Principal angle of rotation (on [0,2*pi])
Quaternion()
Default constructor.
Quaternion & left_multiply_by_inverse_of(Quaternion const &q, bool const precise=true)
Left multiply by the inverse of a Quaternion.
Value const & z() const
z
T dot(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
Quaternion & conjugate()
Conjugate.
Unit quaternion 3-D orientation representation.