OpenLexocad  28.0
DualQuaternion.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2019 Viktor Titov (DeepSOIC) <vv.titov@gmail.com> *
3  * *
4  * This file is part of the FreeCAD CAx development system. *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Library General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Library General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Library General Public *
17  * License along with this library; see the file COPYING.LIB. If not, *
18  * write to the Free Software Foundation, Inc., 59 Temple Place, *
19  * Suite 330, Boston, MA 02111-1307, USA *
20  * *
21  ***************************************************************************/
22 
23 #ifndef FREECAD_BASE_DUAL_QUATERNION_H
24 #define FREECAD_BASE_DUAL_QUATERNION_H
25 
26 #include <Base/DualNumber.h>
27 
28 namespace Base {
29 
41 class LX_BASE_EXPORT DualQuat {
42 public:
43  DualNumber x;
44  DualNumber y;
45  DualNumber z;
46  DualNumber w;
47 public:
49  DualQuat(){}
50  DualQuat(DualNumber x, DualNumber y, DualNumber z, DualNumber w)
51  : x(x), y(y), z(z), w(w) {}
52  DualQuat(double x,double y,double z,double w,double dx,double dy,double dz,double dw)
53  : x(x, dx), y(y, dy), z(z, dz), w(w, dw) {}
54  DualQuat(double x,double y,double z,double w)
55  : x(x), y(y), z(z), w(w) {}
56 
58  DualQuat(DualQuat re, DualQuat du);
59 
61  static DualQuat identity() {return DualQuat(0.0, 0.0, 0.0, 1.0);}
62 
64  DualQuat real() const {return DualQuat(x.re, y.re, z.re, w.re);}
65 
67  DualQuat dual() const {return DualQuat(x.du, y.du, z.du, w.du);}
68 
70  DualQuat conj() const {return DualQuat(-x, -y, -z, w);}
71 
73  DualQuat vec() const {return DualQuat(x,y,z,0.0);}
74 
76  double length() const {return sqrt(x.re*x.re + y.re*y.re + z.re*z.re + w.re*w.re);}
77 
79  double theta() const {return 2.0 * atan2(vec().length(), w.re);}
80 
82  static double dot(DualQuat a, DualQuat b);
83 
85  DualQuat pow(double t, bool shorten = true) const;
86 
87  DualQuat operator-() const {return DualQuat(-x, -y, -z, -w);}
88 
89  //DEBUG
90  //void print() const {
91  // Console().Log("%f, %f, %f, %f; %f, %f, %f, %f", x.re,y.re,z.re,w.re, x.du,y.du,z.du, w.du);
92  //}
93 };
94 
98 
99 DualQuat operator*(DualQuat a, double b);
100 DualQuat operator*(double a, DualQuat b);
103 
104 
105 } //namespace
106 
107 #endif
Base::DualNumber
Dual Numbers aer 2-part numbers like complex numbers, but different algebra. They are denoted as a + ...
Definition: DualNumber.h:59
Base::pow
DualNumber pow(DualNumber a, double pw)
Definition: DualNumber.h:108
DualNumber.h
Base::operator*
DualNumber operator*(DualNumber a, DualNumber b)
Definition: DualNumber.h:91
Base::operator-
DualNumber operator-(DualNumber a, DualNumber b)
Definition: DualNumber.h:81
Base::operator+
DualNumber operator+(DualNumber a, DualNumber b)
Definition: DualNumber.h:71
Base::DualQuat
The DualQuat class represents a dual quaternion, as a quaternion of dual number components....
Definition: DualQuaternion.h:61
Base
Definition: AbstractXMLReader.h:5