GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Quaternion.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _GranOO_libGeom_QUATERNION_hpp_
31 #define _GranOO_libGeom_QUATERNION_hpp_
32 
33 #include <cmath>
34 #include <iostream>
35 #include "GranOO3/3rdParty/Eigen/Dense"
36 #include <boost/archive/text_oarchive.hpp>
37 #include <boost/archive/text_iarchive.hpp>
38 
39 #include "GranOO3/Geom/Vector.hpp"
40 
41 
42 
43 class TiXmlElement;
44 
45 namespace GranOO3
46 {
47  namespace Geom
48  {
49  class Tensor;
50  class EulerAngle;
51 
52 
53  class Quaternion
54  {
55 
56  //Friend operator
57  friend std::ostream& operator<< (std::ostream& , const Quaternion&);
58  friend Quaternion slerp (const Quaternion& , const Quaternion&, const double& ratio);
59  friend Quaternion operator* (const Quaternion& , const Vector& );
60  friend Quaternion operator* (const Vector & , const Quaternion &);
61  friend Quaternion operator* (const Quaternion &, const Quaternion &);
62  friend Quaternion operator* (const Quaternion &, const double & );
63  friend Quaternion operator* (const double & , const Quaternion &);
64  friend Quaternion operator+ (const Quaternion &, const Quaternion &);
65  friend Quaternion operator- (const Quaternion &, const Quaternion &);
66  friend bool operator== (const Quaternion &, const Quaternion &);
67  public:
68  // Usefull for internal use only, NOT DOCUMENTED !
69  static Quaternion& glob(const std::string& id);
70  static std::string class_ID() {return "Quaternion";}
71  static Quaternion* new_object(const TiXmlElement* el);
72  static const Quaternion& global;
73  static const Quaternion& null;
74  static const int N = 4;
75 
76  public:
77  // Constructors and destructor
79  Quaternion(const Vector& axis, double angle);
80  explicit Quaternion(const Vector& v);
81  Quaternion(double vx, double vy, double vz, double s);
83  Quaternion(const Quaternion& q, const Frame& from, const Frame& to);
84  Quaternion(const Vector& from, const Vector& to);
86 
87  // Axis angle formalism
88  void set_axis_angle(const Vector& axis, double angle);
89  void set_angle(double angle);
90  void set_vec_from_to(const Vector& from, const Vector& to);
91  Vector get_axis() const;
92  double get_angle() const;
93  void get_axis_angle(Vector& axis, double& angle) const;
94 
95  // EulerAngle conversion
96  void to_euler_angle(EulerAngle&) const;
97  EulerAngle to_euler_angle() const;
98  Quaternion & operator=(const EulerAngle &);
99 
100  // Accessors and mutators to components
101  void set_value(double q0, double q1, double q2, double q3);
102 
103  // Component
104  double & x();
105  const double & x() const;
106  double & y();
107  const double & y() const;
108  double & z();
109  const double & z() const;
110  double & r();
111  const double & r() const;
112 
113 
114  // Component (for python wrapper)
115  void set_x(const double&);
116  void set_y(const double&);
117  void set_z(const double&);
118  void set_r(const double&);
119 
120  // Component (for python wrapper)
121  double get_x() const;
122  double get_y() const;
123  double get_z() const;
124  double get_r() const;
125 
126 
127  template <typename Axis> double& val();
128  template <typename Axis> const double& val() const;
129 
130  const double& operator()(unsigned int i) const;
131  double& operator()(unsigned int i);
132 
133 
134  // Internal operators
136  void operator*=(const Quaternion& Q);
137  void operator*=(const Vector& v);
138  void operator*=(const double& d);
139  void operator+=(const Quaternion& Q);
140  void operator-=(const Quaternion& Q);
141 
142  // rotate vectors
143  Vector rotate(const Vector & v_in) const;
144  Vector inverse_rotate(const Vector & v_in) const;
145  void rotate(const Vector & v_in, Vector & v_out) const;
146  void inverse_rotate(const Vector & v_in, Vector & v_out) const;
147 
148 
149  // Miscellaneous usefull methods
150  bool is_nan() const;
151  void clear();
152  void clear_unit();
154  Tensor to_rotation_matrix() const;
155  Vector to_vector() const;
156 
157  // Normalization
158  double norm() const;
159  double squared_norm() const;
160  double normalize();
162  bool is_unit() const;
163 
164  // Misc
165  std::string info() const;
166  void add_glob(const std::string& id);
167 
168  private:
169  void equalize(const Quaternion &);
170  // - BOOST SERIALIZATION - //
172  template<class Archive> void serialize(Archive & ar, const unsigned int );
173 
174  public:
175  Eigen::Matrix<double, 4, 1> coord;
176  };
177 
178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
179 
180  // - BOOST SERIALIZATION - //
181 
182  template<class Archive>
183  void
184  Quaternion::serialize(Archive & ar, const unsigned int ) {
185  ar & x(); ar & y(); ar & z(); ar & coord(3);
186  }
187 
188  //EXTERN OPERATOR
189  std::ostream & operator<< (std::ostream& o, const Quaternion& q);
190  Quaternion slerp (const Quaternion& , const Quaternion&, const double& ratio);
191  Quaternion operator* (const Quaternion& , const Vector & );
192  Quaternion operator* (const Vector & , const Quaternion &);
193  Quaternion operator* (const Quaternion &, const Quaternion &);
194  Quaternion operator* (const Quaternion &, const double & );
195  Quaternion operator* (const double & , const Quaternion &);
196  Quaternion operator+ (const Quaternion &, const Quaternion &);
197  Quaternion operator- (const Quaternion &, const Quaternion &);
198  bool operator== (const Quaternion &, const Quaternion &);
199 
200  inline
201  Quaternion::Quaternion(const Vector &from, const Vector &to)
202  : coord() {
203  set_vec_from_to(from,to);
204  }
205 
206  inline
208  : coord() {
209  }
210 
211  inline
212  Quaternion::Quaternion(const Vector& axis, double angle)
213  : coord() {
214  set_axis_angle(axis, angle);
215  }
216 
217  inline
218  Quaternion::Quaternion(double q0, double q1, double q2, double real)
219  : coord(q0, q1, q2, real){
220  }
221 
222  inline
223  Quaternion::Quaternion(const Quaternion& Q)
224  : coord(Q.coord) {
225  }
226 
227  inline
229  }
230 
231  inline double &
232  Quaternion::x() {
233  return coord(0);
234  }
235 
236  inline const double &
237  Quaternion::x() const {
238  return coord(0);
239  }
240 
241  inline double &
242  Quaternion::y() {
243  return coord(1);
244  }
245 
246  inline const double &
247  Quaternion::y() const {
248  return coord(1);
249  }
250 
251  inline double &
252  Quaternion::z() {
253  return coord(2);
254  }
255 
256  inline const double &
257  Quaternion::z() const {
258  return coord(2);
259  }
260 
261  inline double &
262  Quaternion::r() {
263  return coord(3);
264  }
265 
266  inline const double &
267  Quaternion::r() const {
268  return coord(3);
269  }
270 
271  inline void
272  Quaternion::set_x(const double& val) {
273  x() = val;
274  }
275 
276  inline void
277  Quaternion::set_y(const double& val) {
278  y() = val;
279  }
280 
281  inline void
282  Quaternion::set_z(const double& val) {
283  z() = val;
284  }
285 
286  inline void
287  Quaternion::set_r(const double& val) {
288  coord(3) = val;
289  }
290 
291  inline double
292  Quaternion::get_x() const {
293  return x();
294  }
295 
296  inline double
297  Quaternion::get_y() const {
298  return y();
299  }
300 
301  inline double
302  Quaternion::get_z() const {
303  return z();
304  }
305 
306  inline double
307  Quaternion::get_r() const {
308  return coord(3);
309  }
310 
311  template<typename Axis> inline
312  double& Quaternion::val() {
313  SafeModeAssert(0, "Non specilized method is forbidden");
314  return coord(3);
315  }
316 
317  template<typename Axis> inline
318  const double& Quaternion::val() const {
319  SafeModeAssert(0, "Non specilized method is forbidden");
320  return coord(3);
321  }
322 
323  template<> inline
324  double& Quaternion::val<X>() {
325  return x();
326  }
327 
328  template<> inline
329  const double& Quaternion::val<X>() const {
330  return x();
331  }
332 
333  template<> inline
334  double& Quaternion::val<Y>() {
335  return y();
336  }
337 
338  template<> inline
339  const double& Quaternion::val<Y>() const {
340  return y();
341  }
342 
343  template<> inline
344  double& Quaternion::val<Z>() {
345  return z();
346  }
347 
348  template<> inline
349  const double& Quaternion::val<Z>() const {
350  return z();
351  }
352 
353  template<> inline
354  double& Quaternion::val<R>() {
355  return coord(3);
356  }
357 
358  template<> inline
359  const double& Quaternion::val<R>() const {
360  return coord(3);
361  }
362 
363  inline const double&
364  Quaternion::operator() (unsigned int i) const {
365  SafeModeAssert(i < 4, "The component must be in [0, 3] range");
366  return coord(i);
367  }
368 
369  inline double&
370  Quaternion::operator() (unsigned int i) {
371  SafeModeAssert(i < 4, "The component must be in [0, 3] range");
372  return coord(i);
373  }
374 
375 
376  inline void
377  Quaternion::set_vec_from_to(const Vector& from, const Vector& to) {
378  const float epsilon = 1E-10f;
379 
380  const float fromSqNorm = (float)(from.squared_norm());
381  const float toSqNorm = (float)(to.squared_norm());
382  // Identity Quaternion when one vector is null
383  if ((fromSqNorm < epsilon) || (toSqNorm < epsilon)) {
384  x() = y() = z() = 0.;
385  r() = 1.;
386  } else {
387  Vector axis = from^to;
388  const float axisSqNorm = (float)(axis.squared_norm());
389 
390  // Aligned vectors, pick any axis, not aligned with from or to
391  if (axisSqNorm < epsilon) {
392  axis = from.orthogonal_vector();
393  }
394 
395  double angle = asin(sqrt(axisSqNorm / (fromSqNorm * toSqNorm)));
396 
397  if (from*to < 0.0) {
398  angle = M_PI-angle;
399  }
400 
401  set_axis_angle(axis, angle);
402  }
403 
404  }
405 
406  inline void
407  Quaternion::set_axis_angle(const Vector& axis, double angle) {
408  const double norm = axis.norm();
409  // if (norm < epsilon)
410  // {
411  // x = 0.0;
412  // y = 0.0;
413  // z = 0.0;
414  // r = 1.0;
415  // }
416  // else
417  // {
418  const double sin_half_angle = sin(angle / 2.0);
419  x() = sin_half_angle*axis.x()/norm;
420  y() = sin_half_angle*axis.y()/norm;
421  z() = sin_half_angle*axis.z()/norm;
422  r() = cos(angle / 2.0);
423  //}
424  }
425 
426  inline void
427  Quaternion::set_angle(double angle) {
428  const Geom::Vector axis = get_axis();
429  const double sin_half_angle = sin(angle / 2.0);
430  x() = sin_half_angle*axis.x();
431  y() = sin_half_angle*axis.y();
432  z() = sin_half_angle*axis.z();
433  r() = cos(angle / 2.0);
434  }
435 
436 
437 
438 
439  inline
440  std::ostream&
441  operator<<(std::ostream& o, const Quaternion& q) {
442  return o << q.x() << '\t' << q.y() << '\t' << q.z() << '\t' << q.r();
443  }
444 
445  inline
446  Geom::Quaternion
447  slerp(const Quaternion& q0, const Quaternion& q1, const double& ratio) {
448  const double one = 1.0 - std::numeric_limits<double>::epsilon();
449  double d = q0.x()*q1.x() + q0.y()*q1.y() + q0.z()*q1.z() + q0.r()*q1.r();
450  double absD = abs(d);
451  double scale0;
452  double scale1;
453  if(absD >= one) {
454  scale0 = 1.0 - ratio;
455  scale1 = ratio;
456  } else {
457  double theta = acos(absD);
458  double sinTheta = sin(theta);
459  scale0 = sin((1.0 - ratio) * theta) / sinTheta;
460  scale1 = sin((ratio * theta)) / sinTheta;
461  }
462 
463  if(d<0.0)
464  scale1 = -scale1;
465  return Quaternion(scale0 * q0 + scale1 * q1);
466  }
467 
468 
469  inline
470  Quaternion
471  operator*(const Quaternion& q1, const Quaternion& q2) {
472  return Quaternion (q1.r()*q2.x() + q1.x()*q2.r() + q1.y()*q2.z() - q1.z()*q2.y(),
473  q1.r()*q2.y() + q1.y()*q2.r() + q1.z()*q2.x() - q1.x()*q2.z(),
474  q1.r()*q2.z() + q1.z()*q2.r() + q1.x()*q2.y() - q1.y()*q2.x(),
475  q1.r()*q2.r() - q1.x()* q2.x() - q1.y()*q2.y() - q1.z()*q2.z());
476  }
477 
478  inline
479  Quaternion
480  operator*(const Quaternion& q, const Vector& v) {
481  return Quaternion(q.r()*v.x() + q.y()*v.z() - q.z()*v.y(),
482  q.r()*v.y() + q.z()*v.x() - q.x()*v.z(),
483  q.r()*v.z() + q.x()*v.y() - q.y()*v.x(),
484  -v.x()*q.x() - q.y()*v.y() - q.z()*v.z() );
485  }
486 
487  inline
488  Quaternion
489  operator* (const Vector& v, const Quaternion& q) {
490  return Quaternion(q.r()*v.x() + v.y()*q.z() - v.z()*q.y(),
491  q.r()*v.y() + v.z()*q.x() - v.x()*q.z(),
492  q.r()*v.z() + v.x()*q.y() - v.y()*q.x(),
493  -q.x()*v.x() - v.y()*q.y() - v.z()*q.z());
494  }
495 
496  inline
497  Quaternion
498  operator* (const Quaternion& q, const double& d) {
499  return Quaternion( q.x()*d, q.y()*d, q.z()*d, q.r()*d );
500  }
501 
502  inline
503  Quaternion
504  operator* (const double& d, const Quaternion& q) {
505  return Quaternion( q.x()*d, q.y()*d, q.z()*d, q.r()*d );
506  }
507 
508  inline
509  Quaternion
510  operator+ (const Quaternion& q1, const Quaternion& q2) {
511  return Quaternion( q1.x()+q2.x(), q1.y()+q2.y(), q1.z()+q2.z(), q1.r()+q2.r() );
512  }
513 
514  inline
515  bool
516  operator== (const Quaternion& q1, const Quaternion& q2) {
517  const double x = q1.x() - q2.x();
518  const double y = q1.y() - q2.y();
519  const double z = q1.z() - q2.z();
520  const double r = q1.r() - q2.r();
521  const double n = pow(x,2) + pow(y,2) + pow(z,2) + pow(r,2);
522  return n < constant::epsilon;
523  }
524 
525 
526  inline
527  Quaternion
528  operator- (const Quaternion& q1, const Quaternion& q2) {
529  return Quaternion( q1.x()-q2.x(), q1.y()-q2.y(), q1.z()-q2.z(), q1.r()-q2.r() );
530  }
531 
532  inline
533  void
534  Quaternion::set_value(double q0, double q1, double q2, double q3) {
535  x() = q0;
536  y() = q1;
537  z() = q2;
538  r() = q3;
539  }
540 
541  inline
542  Quaternion& Quaternion::operator=(const Quaternion& Q) {
543  x() = Q.x();
544  y() = Q.y();
545  z() = Q.z();
546  r() = Q.r();
547  return (*this);
548  }
549 
550  inline
551  void
552  Quaternion::operator*=(const Vector &v) {
553  const double q0(x());
554  const double q1(y());
555  const double q2(z());
556  const double real(r());
557  x() = real*v.x() + q1*v.z() - q2*v.y();
558  y() = real*v.y() + q2*v.x() - q0*v.z();
559  z() = real*v.z() + q0*v.y() - q1*v.x();
560  r () = -v.x()*q0 - q1*v.y() - q2*v.z();
561  }
562 
563  inline
564  void
565  Quaternion::operator*=(const double &d) {
566  x() *= d;
567  y() *= d;
568  z() *= d;
569  r() *= d;
570  }
571 
572  inline
573  void
574  Quaternion::operator*=(const Quaternion &q) {
575  const double q0(x());
576  const double q1(y());
577  const double q2(z());
578  const double real(r());
579  x() = real*q.x() + q0*q.r() + q1*q.z() - q2*q.y();
580  y() = real*q.y() + q1*q.r() + q2*q.x() - q0*q.z();
581  z() = real*q.z() + q2*q.r() + q0*q.y() - q1*q.x();
582  r() = real*q.r() - q0*q.x() - q1*q.y() - q2*q.z();
583  }
584 
585  inline
586  void
587  Quaternion::operator+=(const Quaternion &Q) {
588  x() += Q.x();
589  y() += Q.y();
590  z() += Q.z();
591  r() += Q.r();
592  }
593 
594  inline
595  void
596  Quaternion::operator-=(const Quaternion &Q) {
597  x() -= Q.x();
598  y() -= Q.y();
599  z() -= Q.z();
600  r() -= Q.r();
601  }
602 
603  inline
604  Quaternion
605  Quaternion::conjugate() const {
606  return Quaternion (-x(), -y(), -z(), r());
607  }
608 
609  inline
610  double
611  Quaternion::squared_norm() const {
612  return (x()*x() + y()*y() + z()*z() + r()*r());
613  }
614 
615  inline
616  double
617  Quaternion::norm() const {
618  return sqrt(x()*x() + y()*y() + z()*z() + r()*r());
619  }
620 
621  inline
622  double
624  const double norm = sqrt(x()*x() + y()*y() + z()*z() + r()*r());
625  x() /= norm;
626  y() /= norm;
627  z() /= norm;
628  r() /= norm;
629  return norm;
630  }
631 
632  inline
633  Quaternion
634  Quaternion::normalized() const {
635  double Q[4];
636  const double norm = sqrt(x()*x() + y()*y() + z()*z() + r()*r());
637  Q[0] = x() / norm;
638  Q[1] = y() / norm;
639  Q[2] = z() / norm;
640  Q[3] = r() / norm;
641  return Quaternion(Q[0], Q[1], Q[2], Q[3]);
642  }
643 
644  inline
645  bool
646  Quaternion::is_unit() const {
647  return (fabs(x()*x() + y()*y() + z()*z()+ r()*r())-1.0f) < 1.0e-8f;
648  }
649 
650  inline
651  void
652  Quaternion::rotate(const Vector& v_in, Vector& v_out) const {
653  const double q00 = 2.0 * x() * x();
654  const double q11 = 2.0 * y() * y();
655  const double q22 = 2.0 * z() * z();
656  const double q01 = 2.0 * x() * y();
657  const double q02 = 2.0 * x() * z();
658  const double q03 = 2.0 * x() * r();
659  const double q12 = 2.0 * y() * z();
660  const double q13 = 2.0 * y() * r();
661  const double q23 = 2.0 * z() * r();
662 
663  v_out.x() = (1.0 - q11 - q22) * (v_in.x()) + (q01 - q23) * v_in.y() + (q02 + q13) * v_in.z();
664  v_out.y() = (q01 + q23) * v_in.x() + (1.0 - q22 - q00) * v_in.y() + (q12 - q03) * v_in.z();
665  v_out.z() = (q02 - q13) * v_in.x() + (q12 + q03) * v_in.y() + (1.0 - q11 - q00) * v_in.z();
666  }
667 
668  inline
669  void
670  Quaternion::inverse_rotate(const Vector & v_in, Vector & v_out) const {
671  const double q00 = 2.0 * x() * x();
672  const double q11 = 2.0 * y() * y();
673  const double q22 = 2.0 * z() * z();
674  const double q01 = 2.0 * x() * y();
675  const double q02 = 2.0 * x() * z();
676  const double q03 = -2.0 * x() * r();
677  const double q12 = 2.0 * y() * z();
678  const double q13 = -2.0 * y() * r();
679  const double q23 = -2.0 * z() * r();
680 
681  v_out.x() = (1.0 - q11 - q22)*v_in.x() + (q01 - q23)*v_in.y() + (q02 + q13)*v_in.z();
682  v_out.y() = (q01 + q23)*v_in.x() + (1.0 - q22 - q00)*v_in.y() + (q12 - q03)*v_in.z();
683  v_out.z() = (q02 - q13)*v_in.x() + (q12 + q03)*v_in.y() + (1.0 - q11 - q00)*v_in.z();
684  }
685 
686  inline
687  Vector
688  Quaternion::rotate(const Vector & v_in) const {
689  const double q00 = 2.0 * x() * x();
690  const double q11 = 2.0 * y() * y();
691  const double q22 = 2.0 * z() * z();
692  const double q01 = 2.0 * x() * y();
693  const double q02 = 2.0 * x() * z();
694  const double q03 = 2.0 * x() * r();
695  const double q12 = 2.0 * y() * z();
696  const double q13 = 2.0 * y() * r();
697  const double q23 = 2.0 * z() * r();
698 
699  return Vector ((1.0 - q11 - q22)*v_in.x() + (q01 - q23)*v_in.y() + (q02 + q13)*v_in.z(),
700  (q01 + q23)*v_in.x() + (1.0 - q22 - q00)*v_in.y() + (q12 - q03)*v_in.z(),
701  (q02 - q13)*v_in.x() + (q12 + q03)*v_in.y() + (1.0 - q11 - q00)*v_in.z());
702 
703  }
704 
705  inline
706  Vector
707  Quaternion::inverse_rotate(const Vector & v_in) const {
708  const double q00 = 2.0 * x() * x();
709  const double q11 = 2.0 * y() * y();
710  const double q22 = 2.0 * z() * z();
711  const double q01 = 2.0 * x() * y();
712  const double q02 = 2.0 * x() * z();
713  const double q03 = -2.0 * x() * r();
714  const double q12 = 2.0 * y() * z();
715  const double q13 = -2.0 * y() * r();
716  const double q23 = -2.0 * z() * r();
717 
718  return Vector ((1.0 - q11 - q22)*v_in.x() + (q01 - q23)*v_in.y() + (q02 + q13)*v_in.z(),
719  (q01 + q23)*v_in.x() + (1.0 - q22 - q00)*v_in.y() + (q12 - q03)*v_in.z(),
720  (q02 - q13)*v_in.x() + (q12 + q03)*v_in.y() + (1.0 - q11 - q00)*v_in.z());
721  }
722 
723  inline bool
724  Quaternion::is_nan() const {
725  if (x()!=x())
726  return true;
727  if (y()!=y())
728  return true;
729  if (z()!=z())
730  return true;
731  if (r()!=r())
732  return true;
733  return false;
734  }
735 
736  inline
737  void
739  x() = 0.;
740  y() = 0.;
741  z() = 0.;
742  r() = 0.;
743  }
744 
745  inline
746  void
748  x() = 0.;
749  y() = 0.;
750  z() = 0.;
751  r() = 1.;
752  }
753 
754  inline
755  Vector
756  Quaternion::to_vector() const {
757  return Vector(x(),y(),z());
758  }
759 
760  inline
761  void
762  Quaternion::equalize(const Quaternion &Q) {
763  x() = Q.x();
764  y() = Q.y();
765  z() = Q.z();
766  r() = Q.r();
767  }
768 
769  inline
770  Quaternion::Quaternion(const Vector& v)
771  : coord(v.x(), v.y(), v.z(), 0.) {
772  }
773 
774 
775 #endif
776  }
777 }
778 
779 #endif
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
Definition: EulerAngle.hpp:61
Definition: Frame.hpp:68
Definition: Quaternion.hpp:54
void operator*=(const Quaternion &Q)
void get_axis_angle(Vector &axis, double &angle) const
Definition: Quaternion.cpp:131
friend std::ostream & operator<<(std::ostream &, const Quaternion &)
void set_y(const double &)
friend Quaternion operator+(const Quaternion &, const Quaternion &)
Tensor to_rotation_matrix() const
Definition: Quaternion.cpp:137
static Quaternion & glob(const std::string &id)
Definition: Quaternion.cpp:45
Eigen::Matrix< double, 4, 1 > coord
Definition: Quaternion.hpp:175
Vector to_vector() const
static std::string class_ID()
Definition: Quaternion.hpp:70
friend Quaternion operator*(const Quaternion &, const Vector &)
void operator+=(const Quaternion &Q)
double & operator()(unsigned int i)
void operator*=(const Vector &v)
double get_angle() const
Definition: Quaternion.cpp:115
Quaternion(const Vector &axis, double angle)
const double & r() const
void set_vec_from_to(const Vector &from, const Vector &to)
void set_z(const double &)
Vector inverse_rotate(const Vector &v_in) const
friend Quaternion slerp(const Quaternion &, const Quaternion &, const double &ratio)
const double & x() const
void set_r(const double &)
std::string info() const
Definition: Quaternion.cpp:176
EulerAngle to_euler_angle() const
Definition: Quaternion.cpp:94
const double & z() const
Quaternion normalized() const
friend Quaternion operator-(const Quaternion &, const Quaternion &)
void operator*=(const double &d)
Quaternion(double vx, double vy, double vz, double s)
void add_glob(const std::string &id)
Definition: Quaternion.cpp:183
const double & operator()(unsigned int i) const
friend bool operator==(const Quaternion &, const Quaternion &)
Quaternion & operator=(const EulerAngle &)
Definition: Quaternion.cpp:102
Quaternion(const Vector &v)
void operator-=(const Quaternion &Q)
const double & val() const
void inverse_rotate(const Vector &v_in, Vector &v_out) const
const double & y() const
void equalize(const Quaternion &)
static const int N
Definition: Quaternion.hpp:74
void set_axis_angle(const Vector &axis, double angle)
void serialize(Archive &ar, const unsigned int)
Quaternion conjugate() const
Vector get_axis() const
Definition: Quaternion.cpp:110
friend class boost::serialization::access
Definition: Quaternion.hpp:171
Quaternion(const Vector &from, const Vector &to)
double squared_norm() const
void set_value(double q0, double q1, double q2, double q3)
static const Quaternion & global
Definition: Quaternion.hpp:72
void set_angle(double angle)
Vector rotate(const Vector &v_in) const
static Quaternion * new_object(const TiXmlElement *el)
Definition: Quaternion.cpp:156
void rotate(const Vector &v_in, Vector &v_out) const
void set_x(const double &)
Quaternion(const Quaternion &q)
Quaternion & operator=(const Quaternion &Q)
Definition: Tensor.hpp:62
Definition: Vector.hpp:75
SymTensor operator+(const SymTensor &m1, const SymTensor &m2)
SymTensor operator-(const SymTensor &m1, const SymTensor &m2)
std::ostream & operator<<(std::ostream &, const EulerAngle &)
Vector operator*(const SymTensor &m, const Vector &v)
bool operator==(const EulerAngle &, const EulerAngle &)
Definition: Common.hpp:198
T pow(const T v0, const T v1)
Definition: Exprtk.hpp:1491
x y * z
Definition: Exprtk.hpp:11139
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
Definition: Constant.hpp:48
static double epsilon
Definition: Constant.hpp:58