Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Quaternion.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/Quaternion.hh
11 /// @brief Unit quaternion 3-D orientation representation
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 
14 
15 #ifndef INCLUDED_numeric_Quaternion_hh
16 #define INCLUDED_numeric_Quaternion_hh
17 
18 
19 // Unit headers
21 
22 // Package headers
23 #include <numeric/NumericTraits.hh>
24 #include <numeric/xyzVector.hh>
26 
27 // C++ headers
28 #include <utility/assert.hh>
29 #include <cmath>
30 
31 
32 namespace numeric {
33 
34 
35 /// @brief Unit quaternion 3-D orientation representation
36 ///
37 /// @remarks
38 /// @li Quaternion defined as ( w, x, y, z )
39 /// @li Quaternions must be in the same coordinate frame to be used together
40 /// @li Successive rotation convention: q2 * q1 means q1 followed by q2
41 /// @li Performance-critical code can suppress normalization after every modification
42 /// and use explicit normalization
43 template< typename T >
44 class Quaternion
45 {
46 
47 
48 private: // Friends
49 
50 
51  friend class BodyPosition< T >;
52 
53 
54 public: // Types
55 
56 
57  // Project style
58  typedef T Value;
59  typedef T & Reference;
60  typedef T const & ConstReference;
61  typedef T * Pointer;
62  typedef T const * ConstPointer;
63 
64  // STL/boost style
65  typedef T value_type;
66  typedef T & reference;
67  typedef T const & const_reference;
68  typedef T * pointer;
69  typedef T const * const_pointer;
70 
71  // Traits
73 
74  // Math
76 
77 
78 public: // Creation
79 
80 
81  /// @brief Default constructor
82  inline
83  Quaternion() : // Sets to identity
84  w_( T( 1 ) ),
85  x_( T( 0 ) ),
86  y_( T( 0 ) ),
87  z_( T( 0 ) )
88  {}
89 
90 
91  /// @brief Coordinate constructor
92  inline
94  Value const & w_a,
95  Value const & x_a,
96  Value const & y_a,
97  Value const & z_a,
98  bool const precise = true
99  ) :
100  w_( w_a ),
101  x_( x_a ),
102  y_( y_a ),
103  z_( z_a )
104  {
105  assert( is_normalized() );
106  if ( precise ) normalize();
107  }
108 
109 
110  /// @brief Identity named constructor
111  inline
112  static
113  Quaternion
115  {
116  return Quaternion( T( 1 ), T( 0 ), T( 0 ), T( 0 ) );
117  }
118 
119 
120  /// @brief Copy constructor
121  inline
122  Quaternion( Quaternion const & q ) :
123  w_( q.w_ ),
124  x_( q.x_ ),
125  y_( q.y_ ),
126  z_( q.z_ )
127  {}
128 
129 
130  /// @brief Destructor
131  inline
133  {}
134 
135 
136 public: // copy assignment
137 
138  inline
139  Quaternion &
140  operator =( Quaternion const & q )
141  {
142  if ( this != &q ) {
143  w_ = q.w_;
144  x_ = q.x_;
145  y_ = q.y_;
146  z_ = q.z_;
147  }
148  return *this;
149  }
150 
151 
152 public: // Properties
153 
154 
155  /// @brief w
156  inline
157  Value const &
158  w() const
159  {
160  return w_;
161  }
162 
163 
164  /// @brief x
165  inline
166  Value const &
167  x() const
168  {
169  return x_;
170  }
171 
172 
173  /// @brief y
174  inline
175  Value const &
176  y() const
177  {
178  return y_;
179  }
180 
181 
182  /// @brief z
183  inline
184  Value const &
185  z() const
186  {
187  return z_;
188  }
189 
190 
191  /// @brief w squared
192  inline
193  Value
194  w_squared() const
195  {
196  return w_ * w_;
197  }
198 
199 
200  /// @brief x squared
201  inline
202  Value
203  x_squared() const
204  {
205  return x_ * x_;
206  }
207 
208 
209  /// @brief y squared
210  inline
211  Value
212  y_squared() const
213  {
214  return y_ * y_;
215  }
216 
217 
218  /// @brief z squared
219  inline
220  Value
221  z_squared() const
222  {
223  return z_ * z_;
224  }
225 
226 
227  /// @brief Norm: Should be one
228  inline
229  Value
230  norm() const
231  {
232  return std::sqrt( ( w_ * w_ ) + ( x_ * x_ ) + ( y_ * y_ ) + ( z_ * z_ ) );
233  }
234 
235 
236  /// @brief Norm squared: Should be one
237  inline
238  Value
239  norm_squared() const
240  {
241  return ( ( w_ * w_ ) + ( x_ * x_ ) + ( y_ * y_ ) + ( z_ * z_ ) );
242  }
243 
244 
245  /// @brief Norm error
246  inline
247  Value
248  norm_error() const
249  {
250  return std::abs( T( 1 ) - norm() );
251  }
252 
253 
254  /// @brief Norm squared error
255  inline
256  Value
258  {
259  return std::abs( T( 1 ) - norm_squared() );
260  }
261 
262 
263  /// @brief Magnitude: Should be one
264  inline
265  Value
266  magnitude() const
267  {
268  return std::sqrt( ( w_ * w_ ) + ( x_ * x_ ) + ( y_ * y_ ) + ( z_ * z_ ) );
269  }
270 
271 
272  /// @brief Magnitude squared: Should be one
273  inline
274  Value
276  {
277  return ( ( w_ * w_ ) + ( x_ * x_ ) + ( y_ * y_ ) + ( z_ * z_ ) );
278  }
279 
280 
281  /// @brief Magnitude error
282  inline
283  Value
285  {
286  return std::abs( T( 1 ) - magnitude() );
287  }
288 
289 
290  /// @brief Magnitude squared error
291  inline
292  Value
294  {
295  return std::abs( T( 1 ) - magnitude_squared() );
296  }
297 
298 
299  /// @brief Magnitude squared error within tolerance?
300  inline
301  bool
302  is_normalized( Value const & tol = Traits::quaternion_tolerance() ) const
303  {
304  return ( norm_squared_error() <= tol );
305  }
306 
307 
308  /// @brief Magnitude squared error exceeds tolerance?
309  inline
310  bool
311  not_normalized( Value const & tol = Traits::quaternion_tolerance() ) const
312  {
313  return ( norm_squared_error() > tol );
314  }
315 
316 
317  /// @brief Principal angle of rotation (on [0,2*pi])
318  inline
319  Value
320  angle() const
321  {
322  return T( 2 ) * std::acos( w_ );
323  }
324 
325 
326  /// @brief Axis of Rotation unit vector (direction for angle on [0,2*pi])
327  inline
328  Axis
329  axis() const
330  {
331  return Axis( x_, y_, z_ ).normalize_or_zero(); // Returns zero vector if angle is zero
332  }
333 
334 
335  /// @brief Axis of rotation unit vector: Passed vector (direction for angle on [0,2*pi])
336  inline
337  Axis &
338  axis( Axis & u ) const
339  {
340  return u.assign( x_, y_, z_ ).normalize_or_zero(); // Returns zero vector if angle is zero
341  }
342 
343 
344 public: // Methods
345 
346 
347  /// @brief Dot product
348  inline
349  Value
350  dot( Quaternion const & q ) const
351  {
352  return ( w_ * q.w_ ) + ( x_ * q.x_ ) + ( y_ * q.y_ ) + ( z_ * q.z_ );
353  }
354 
355 
356  /// @brief Dot product
357  inline
358  Value
359  dot_product( Quaternion const & q ) const
360  {
361  return ( w_ * q.w_ ) + ( x_ * q.x_ ) + ( y_ * q.y_ ) + ( z_ * q.z_ );
362  }
363 
364 
365 public: // Methods: modifiers
366 
367 
368  /// @brief Normalize
369  inline
370  Quaternion &
372  {
373  Value const norm_sq( norm_squared() );
374  if ( norm_sq != T( 1 ) ) {
375  assert( norm_sq > T( 0 ) );
376  Value const norm_inv( T( 1 ) / std::sqrt( norm_sq ) );
377  w_ *= norm_inv;
378  x_ *= norm_inv;
379  y_ *= norm_inv;
380  z_ *= norm_inv;
381  }
382  return *this;
383  }
384 
385 
386  /// @brief Normalize if magnitude squared error exceeds tolerance
387  inline
388  Quaternion &
389  normalize_if_needed( Value const & tol = Traits::quaternion_tolerance() )
390  {
391  Value const norm_sq( norm_squared() );
392  if ( std::abs( T( 1 ) - norm_sq ) > tol ) {
393  assert( norm_sq > T( 0 ) );
394  Value const norm_inv( T( 1 ) / std::sqrt( norm_sq ) );
395  w_ *= norm_inv;
396  x_ *= norm_inv;
397  y_ *= norm_inv;
398  z_ *= norm_inv;
399  }
400  return *this;
401  }
402 
403 
404  /// @brief Identity
405  inline
406  Quaternion &
408  {
409  w_ = T( 1 );
410  x_ = T( 0 );
411  y_ = T( 0 );
412  z_ = T( 0 );
413  return *this;
414  }
415 
416 
417  /// @brief Conjugate
418  inline
419  Quaternion &
421  {
422  x_ = -x_;
423  y_ = -y_;
424  z_ = -z_;
425  return *this;
426  }
427 
428 
429  /// @brief Invert
430  inline
431  Quaternion &
433  {
434  x_ = -x_;
435  y_ = -y_;
436  z_ = -z_;
437  return *this;
438  }
439 
440 
441  /// @brief Apply a successive Quaternion
442  inline
443  Quaternion &
444  apply( Quaternion const & q, bool const precise = true )
445  {
446  return left_multiply_by( q, precise );
447  }
448 
449 
450  /// @brief Left multiply by a Quaternion
451  inline
452  Quaternion &
453  left_multiply_by( Quaternion const & q, bool const precise = true )
454  {
455  Value const w_o( w_ );
456  Value const x_o( x_ );
457  Value const y_o( y_ );
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 );
462  if ( precise ) normalize();
463  return *this;
464  }
465 
466 
467  /// @brief Right multiply by a Quaternion
468  inline
469  Quaternion &
470  right_multiply_by( Quaternion const & q, bool const precise = true )
471  {
472  Value const w_o( w_ );
473  Value const x_o( x_ );
474  Value const y_o( y_ );
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_ );
479  if ( precise ) normalize();
480  return *this;
481  }
482 
483 
484  /// @brief Left multiply by the inverse of a Quaternion
485  inline
486  Quaternion &
487  left_multiply_by_inverse_of( Quaternion const & q, bool const precise = true )
488  {
489  Value const w_o( w_ );
490  Value const x_o( x_ );
491  Value const y_o( y_ );
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 );
496  if ( precise ) normalize();
497  return *this;
498  }
499 
500 
501  /// @brief Right multiply by the inverse of a Quaternion
502  inline
503  Quaternion &
504  right_multiply_by_inverse_of( Quaternion const & q, bool const precise = true )
505  {
506  Value const w_o( w_ );
507  Value const x_o( x_ );
508  Value const y_o( y_ );
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_ );
513  if ( precise ) normalize();
514  return *this;
515  }
516 
517 
518  /// @brief Swap
519  inline
520  void
522  {
523  Value t;
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;
528  }
529 
530 
531 public: // Methods: generators
532 
533 
534  /// @brief Conjugated
535  inline
536  Quaternion
537  conjugated() const
538  {
539  return Quaternion( w_, -x_, -y_, -z_ );
540  }
541 
542 
543  /// @brief Inverse
544  inline
545  Quaternion
546  inverse() const
547  {
548  return Quaternion( w_, -x_, -y_, -z_ );
549  }
550 
551 
552  /// @brief Quaternion * Quaternion
553  friend
554  inline
555  Quaternion
556  operator *( Quaternion const & q2, Quaternion const & q1 )
557  {
558  return Quaternion(
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_ )
563  ).normalize();
564  }
565 
566 
567  /// @brief Product: Quaternion * Quaternion
568  friend
569  inline
570  Quaternion
571  product( Quaternion const & q2, Quaternion const & q1, bool const precise = true )
572  {
573  if ( precise ) { // Return normalized product
574  return Quaternion(
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_ )
579  ).normalize();
580  } else { // Return product
581  return Quaternion(
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_ )
586  );
587  }
588  }
589 
590 
591  /// @brief Identity Quaternion for expressions
592  /// @note Default and identity() named constructors can be faster for construction
593  /// @note Can be safely used in construction of global objects
594  inline
595  static
596  Quaternion const &
597  I()
598  {
599  static Quaternion const I_( T( 1 ), T( 0 ), T( 0 ), T( 0 ) );
600  return I_;
601  }
602 
603 
604 public: // Comparison
605 
606 
607  /// @brief Quaternion == Quaternion
608  friend
609  inline
610  bool
611  operator ==( Quaternion const & q1, Quaternion const & q2 )
612  {
613  return ( ( q1.w_ == q2.w_ ) && ( q1.x_ == q2.x_ ) && ( q1.y_ == q2.y_ ) && ( q1.z_ == q2.z_ ) );
614  }
615 
616 
617  /// @brief Quaternion != Quaternion
618  friend
619  inline
620  bool
621  operator !=( Quaternion const & q1, Quaternion const & q2 )
622  {
623  return ( ( q1.w_ != q2.w_ ) || ( q1.x_ != q2.x_ ) || ( q1.y_ != q2.y_ ) || ( q1.z_ != q2.z_ ) );
624  }
625 
626 
627  /// @brief Dot product
628  friend
629  inline
630  Value
631  dot( Quaternion const & q1, Quaternion const & q2 )
632  {
633  return ( q1.w_ * q2.w_ ) + ( q1.x_ * q2.x_ ) + ( q1.y_ * q2.y_ ) + ( q1.z_ * q2.z_ );
634  }
635 
636 
637  /// @brief Dot product
638  friend
639  inline
640  Value
641  dot_product( Quaternion const & q1, Quaternion const & q2 )
642  {
643  return ( q1.w_ * q2.w_ ) + ( q1.x_ * q2.x_ ) + ( q1.y_ * q2.y_ ) + ( q1.z_ * q2.z_ );
644  }
645 
646 
647 private: // Fields
648 
649 
650  /// @brief w coordinate
652 
653  /// @brief x coordinate
655 
656  /// @brief y coordinate
658 
659  /// @brief z coordinate
661 
662 
663 }; // Quaternion
664 
665 
666 /// @brief Quaternion * Quaternion
667 template< typename T >
669 operator *( Quaternion< T > const & q2, Quaternion< T > const & q1 );
670 
671 
672 /// @brief Product: Quaternion * Quaternion
673 template< typename T >
675 product( Quaternion< T > const & q2, Quaternion< T > const & q1, bool const precise );
676 
677 
678 /// @brief Quaternion == Quaternion
679 template< typename T >
680 bool
681 operator ==( Quaternion< T > const & q1, Quaternion< T > const & q2 );
682 
683 
684 /// @brief Quaternion != Quaternion
685 template< typename T >
686 bool
687 operator !=( Quaternion< T > const & q1, Quaternion< T > const & q2 );
688 
689 
690 /// @brief Dot product
691 template< typename T >
692 T
693 dot( Quaternion< T > const & q1, Quaternion< T > const & q2 );
694 
695 
696 /// @brief Dot product
697 template< typename T >
698 T
699 dot_product( Quaternion< T > const & q1, Quaternion< T > const & q2 );
700 
701 
702 } // namespace numeric
703 
704 
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
Definition: Quaternion.hh:72
Numeric type traits.
xyzVector & assign(Value const &x_a, Value const &y_a, Value const &z_a)
Triple value assignment.
Definition: xyzVector.hh:348
Value dot_product(Quaternion const &q) const
Dot product.
Definition: Quaternion.hh:359
Quaternion inverse() const
Inverse.
Definition: Quaternion.hh:546
Value magnitude_squared() const
Magnitude squared: Should be one.
Definition: Quaternion.hh:275
Value z_squared() const
z squared
Definition: Quaternion.hh:221
Value norm() const
Norm: Should be one.
Definition: Quaternion.hh:230
Value const & w() const
w
Definition: Quaternion.hh:158
NumericTraits: Numeric type traits.
Value norm_squared_error() const
Norm squared error.
Definition: Quaternion.hh:257
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.
Definition: Quaternion.hh:371
Quaternion & apply(Quaternion const &q, bool const precise=true)
Apply a successive Quaternion.
Definition: Quaternion.hh:444
Quaternion & left_multiply_by(Quaternion const &q, bool const precise=true)
Left multiply by a Quaternion.
Definition: Quaternion.hh:453
numeric::BodyPosition forward declarations
friend Value dot_product(Quaternion const &q1, Quaternion const &q2)
Dot product.
Definition: Quaternion.hh:641
Value z_
z coordinate
Definition: Quaternion.hh:660
Value x_
x coordinate
Definition: Quaternion.hh:654
Quaternion(Value const &w_a, Value const &x_a, Value const &y_a, Value const &z_a, bool const precise=true)
Coordinate constructor.
Definition: Quaternion.hh:93
Value w_
w coordinate
Definition: Quaternion.hh:651
Value norm_error() const
Norm error.
Definition: Quaternion.hh:248
Quaternion & right_multiply_by(Quaternion const &q, bool const precise=true)
Right multiply by a Quaternion.
Definition: Quaternion.hh:470
Quaternion & right_multiply_by_inverse_of(Quaternion const &q, bool const precise=true)
Right multiply by the inverse of a Quaternion.
Definition: Quaternion.hh:504
static Quaternion const & I()
Identity Quaternion for expressions.
Definition: Quaternion.hh:597
Value w_squared() const
w squared
Definition: Quaternion.hh:194
Value norm_squared() const
Norm squared: Should be one.
Definition: Quaternion.hh:239
Axis axis() const
Axis of Rotation unit vector (direction for angle on [0,2*pi])
Definition: Quaternion.hh:329
T const & const_reference
Definition: Quaternion.hh:67
Value y_
y coordinate
Definition: Quaternion.hh:657
friend Quaternion product(Quaternion const &q2, Quaternion const &q1, bool const precise=true)
Product: Quaternion * Quaternion.
Definition: Quaternion.hh:571
numeric::Quaternion forward declarations
~Quaternion()
Destructor.
Definition: Quaternion.hh:132
friend bool operator==(Quaternion const &q1, Quaternion const &q2)
Quaternion == Quaternion.
Definition: Quaternion.hh:611
T abs(T const &x)
std::abs( x ) == | x |
Definition: Fmath.hh:295
Value const & x() const
x
Definition: Quaternion.hh:167
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...
Definition: prob_util.hh:56
Value magnitude_squared_error() const
Magnitude squared error.
Definition: Quaternion.hh:293
Value y_squared() const
y squared
Definition: Quaternion.hh:212
Value x_squared() const
x squared
Definition: Quaternion.hh:203
Quaternion & invert()
Invert.
Definition: Quaternion.hh:432
Quaternion conjugated() const
Conjugated.
Definition: Quaternion.hh:537
T const * ConstPointer
Definition: Quaternion.hh:62
Quaternion & to_identity()
Identity.
Definition: Quaternion.hh:407
Value magnitude_error() const
Magnitude error.
Definition: Quaternion.hh:284
Quaternion & operator=(Quaternion const &q)
Definition: Quaternion.hh:140
friend Value dot(Quaternion const &q1, Quaternion const &q2)
Dot product.
Definition: Quaternion.hh:631
Value magnitude() const
Magnitude: Should be one.
Definition: Quaternion.hh:266
static Quaternion identity()
Identity named constructor.
Definition: Quaternion.hh:114
Value dot(Quaternion const &q) const
Dot product.
Definition: Quaternion.hh:350
xyzVector & normalize_or_zero()
Normalize: zero xyzVector if length is zero.
Definition: xyzVector.hh:749
T const * const_pointer
Definition: Quaternion.hh:69
bool operator!=(BodyPosition< T > const &p1, BodyPosition< T > const &p2)
BodyPosition != BodyPosition.
T const & ConstReference
Definition: Quaternion.hh:60
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?
Definition: Quaternion.hh:302
Quaternion & normalize_if_needed(Value const &tol=Traits::quaternion_tolerance())
Normalize if magnitude squared error exceeds tolerance.
Definition: Quaternion.hh:389
float tol
Definition: loops_kic.py:75
friend bool operator!=(Quaternion const &q1, Quaternion const &q2)
Quaternion != Quaternion.
Definition: Quaternion.hh:621
friend Quaternion operator*(Quaternion const &q2, Quaternion const &q1)
Quaternion * Quaternion.
Definition: Quaternion.hh:556
bool not_normalized(Value const &tol=Traits::quaternion_tolerance()) const
Magnitude squared error exceeds tolerance?
Definition: Quaternion.hh:311
Value const & y() const
y
Definition: Quaternion.hh:176
Quaternion(Quaternion const &q)
Copy constructor.
Definition: Quaternion.hh:122
Axis & axis(Axis &u) const
Axis of rotation unit vector: Passed vector (direction for angle on [0,2*pi])
Definition: Quaternion.hh:338
xyzVector< T > Axis
Definition: Quaternion.hh:75
void swap(Quaternion &q)
Swap.
Definition: Quaternion.hh:521
Fast (x,y,z)-coordinate numeric vector.
Value angle() const
Principal angle of rotation (on [0,2*pi])
Definition: Quaternion.hh:320
Quaternion()
Default constructor.
Definition: Quaternion.hh:83
Quaternion & left_multiply_by_inverse_of(Quaternion const &q, bool const precise=true)
Left multiply by the inverse of a Quaternion.
Definition: Quaternion.hh:487
Value const & z() const
z
Definition: Quaternion.hh:185
T dot(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
Quaternion & conjugate()
Conjugate.
Definition: Quaternion.hh:420
Unit quaternion 3-D orientation representation.