- 3.0.2 rigid body dynamics module.
internals.h
Go to the documentation of this file.
1 /* CPYHDR { */
2 /*
3  * This file is part of the 'iit-rbd' library.
4  * Copyright © 2015 2016, Marco Frigerio (marco.frigerio@iit.it)
5  *
6  * See the LICENSE file for more information.
7  */
8 /* } CPYHDR */
9 
10 #ifndef IIT_RBD_INTERNALS_
11 #define IIT_RBD_INTERNALS_
12 
13 #include "InertiaMatrix.h"
14 
15 namespace iit {
16 namespace rbd {
17 namespace internal {
18 
19 /*
20  * A container of the 9 coefficients of a 3x3 matrix.
21  *
22  * When multiple, repeated access to the elements of the matrix is necessary,
23  * copying them once at the beginning in local variables might slightly improve
24  * the performance (coefficient access typically comes at the cost of few
25  * arithmetic operations)
26  */
27 template<typename Scalar>
29 {
31 
34  Scalar yx, Scalar yy, Scalar yz,
35  Scalar zx, Scalar zy, Scalar zz) :
36  XX(xx), XY(xy), XZ(xz),
37  YX(yx), YY(yy), YZ(yz),
38  ZX(zx), ZY(zy), ZZ(zz)
39  {}
40 
41  template <typename D>
43  XX(E(X,X)), XY(E(X,Y)), XZ(E(X,Z)),
44  YX(E(Y,X)), YY(E(Y,Y)), YZ(E(Y,Z)),
45  ZX(E(Z,X)), ZY(E(Z,Y)), ZZ(E(Z,Z))
46  {}
47 
48  template <typename D>
49  void read(const MatrixBase<D>& E)
50  {
51  XX = E(X,X); XY = E(X,Y); XZ = E(X,Z);
52  YX = E(Y,X); YY = E(Y,Y); YZ = E(Y,Z);
53  ZX = E(Z,X); ZY = E(Z,Y); ZZ = E(Z,Z);
54  }
55 };
56 
57 /*
58  * A container of the 6 distinct coefficients of a symmetrix 3x3 matrix.
59  *
60  * See comment above.
61  */
62 template<typename Scalar>
65 
67 
69  Scalar yy, Scalar yz,
70  Scalar zz) :
71  XX(xx), XY(xy), XZ(xz),
72  YY(yy), YZ(yz),
73  ZZ(zz)
74  {}
75 
76  template <typename D>
78  read(E);
79  }
80 
81  template <typename D>
82  void read(const MatrixBase<D>& E)
83  {
84  XX = E(X,X); XY = E(X,Y); XZ = E(X,Z);
85  YY = E(Y,Y); YZ = E(Y,Z);
86  ZZ = E(Z,Z);
87  }
88  template <typename D>
89  void write(const MatrixBase<D>& Econst)
90  {
91  MatrixBase<D>& E = const_cast<MatrixBase<D>&>(Econst);
92  E(X,X) = XX; E(X,Y) = XY; E(X,Z) = XZ;
93  E(Y,X) = XY; E(Y,Y) = YY; E(Y,Z) = YZ;
94  E(Z,X) = XZ; E(Z,Y) = YZ; E(Z,Z) = ZZ;
95  }
96 };
97 
98 /*
99  * Performs the transformation of a symmetrix 3x3 matrix A, with the rotation
100  * matrix E
101  * B = E * A * E^T
102  *
103  * These calculations are documented in the appendix of Roy's book
104  */
105 template<typename Scalar>
106 inline void rot_symmetric_EAET(
110 {
111  Scalar LXX = A.XX - A.ZZ;
112  Scalar LXY = A.XY; // same as LYX
113  Scalar LYY = A.YY - A.ZZ;
114  Scalar LZX = 2*A.XZ;
115  Scalar LZY = 2*A.YZ;
116 
117  Scalar yXX = E.YX*LXX + E.YY*LXY + E.YZ*LZX;
118  Scalar yXY = E.YX*LXY + E.YY*LYY + E.YZ*LZY;
119  Scalar yYX = E.ZX*LXX + E.ZY*LXY + E.ZZ*LZX;
120  Scalar yYY = E.ZX*LXY + E.ZY*LYY + E.ZZ*LZY;
121 
122  Scalar v1 = -A.YZ;
123  Scalar v2 = A.XZ;
124  Scalar EvX = E.XX*v1 + E.XY*v2;
125  Scalar EvY = E.YX*v1 + E.YY*v2;
126  Scalar EvZ = E.ZX*v1 + E.ZY*v2;
127 
128  B.XY = yXX * E.XX + yXY * E.XY + EvZ;
129  B.XZ = yYX * E.XX + yYY * E.XY - EvY;
130  B.YZ = yYX * E.YX + yYY * E.YY + EvX;
131 
132  Scalar zYY = yXX * E.YX + yXY * E.YY;
133  Scalar zZZ = yYX * E.ZX + yYY * E.ZY;
134  B.XX = LXX + LYY - zYY - zZZ + A.ZZ;
135  B.YY = zYY + A.ZZ;
136  B.ZZ = zZZ + A.ZZ;
137 }
138 
139 /*
140  * Performs the transformation of a 3x3 matrix A, with the rotation
141  * matrix E
142  * B = E * A * E^T
143  */
144 template<typename Scalar>
145 inline void rot_EAET(
149 {
150  Scalar LXX = A.XX - A.ZZ;
151  Scalar LXY = A.XY;
152  Scalar LYX = A.YX;
153  Scalar LYY = A.YY - A.ZZ;
154  Scalar LZX = A.ZX + A.XZ;
155  Scalar LZY = A.ZY + A.YZ;
156 
157  Scalar v1 = -A.YZ;
158  Scalar v2 = A.XZ;
159  Scalar EvX = E.XX*v1 + E.XY*v2;
160  Scalar EvY = E.YX*v1 + E.YY*v2;
161  Scalar EvZ = E.ZX*v1 + E.ZY*v2;
162 
163  Scalar yXX = E.XX*LXX + E.XY*LYX + E.XZ*LZX;
164  Scalar yXY = E.XX*LXY + E.XY*LYY + E.XZ*LZY;
165  Scalar yYX = E.YX*LXX + E.YY*LYX + E.YZ*LZX;
166  Scalar yYY = E.YX*LXY + E.YY*LYY + E.YZ*LZY;
167  Scalar yZX = E.ZX*LXX + E.ZY*LYX + E.ZZ*LZX;
168  Scalar yZY = E.ZX*LXY + E.ZY*LYY + E.ZZ*LZY;
169 
170  B.XX = yXX*E.XX + yXY*E.XY + A.ZZ;
171  B.YY = yYX*E.YX + yYY*E.YY + A.ZZ;
172  B.ZZ = yZX*E.ZX + yZY*E.ZY + A.ZZ;
173 
174  B.XY = yXX*E.YX + yXY*E.YY - EvZ;
175  B.YX = yYX*E.XX + yYY*E.XY + EvZ;
176  B.XZ = yXX*E.ZX + yXY*E.ZY + EvY;
177  B.ZX = yZX*E.XX + yZY*E.XY - EvY;
178  B.YZ = yYX*E.ZX + yYY*E.ZY - EvX;
179  B.ZY = yZX*E.YX + yZY*E.YY + EvX;
180 }
181 
182 
183 }
184 }
185 }
186 
187 #endif
Scalar YZ
Definition: internals.h:30
SymmMat3x3Coefficients()
Definition: internals.h:66
Definition: rbd.h:173
Scalar YX
Definition: internals.h:30
Scalar XZ
Definition: internals.h:64
Scalar ZZ
Definition: internals.h:64
ct::core::ADCodegenLinearizer< state_dim, control_dim >::ADCGScalar Scalar
Definition: internals.h:28
Scalar YZ
Definition: internals.h:64
Mat3x3Coefficients(const MatrixBase< D > &E)
Definition: internals.h:42
Mat3x3Coefficients(Scalar xx, Scalar xy, Scalar xz, Scalar yx, Scalar yy, Scalar yz, Scalar zx, Scalar zy, Scalar zz)
Definition: internals.h:33
Mat3x3Coefficients()
Definition: internals.h:32
void read(const MatrixBase< D > &E)
Definition: internals.h:82
Scalar XX
Definition: internals.h:64
Scalar XY
Definition: internals.h:64
SymmMat3x3Coefficients(Scalar xx, Scalar xy, Scalar xz, Scalar yy, Scalar yz, Scalar zz)
Definition: internals.h:68
void rot_symmetric_EAET(const Mat3x3Coefficients< Scalar > &E, const SymmMat3x3Coefficients< Scalar > &A, SymmMat3x3Coefficients< Scalar > &B)
Definition: internals.h:106
Scalar XX
Definition: internals.h:30
Eigen::MatrixBase< Derived > MatrixBase
Definition: rbd.h:51
Scalar YY
Definition: internals.h:30
void read(const MatrixBase< D > &E)
Definition: internals.h:49
Definition: rbd.h:173
void rot_EAET(const Mat3x3Coefficients< Scalar > &E, const Mat3x3Coefficients< Scalar > &A, Mat3x3Coefficients< Scalar > &B)
Definition: internals.h:145
Scalar ZX
Definition: internals.h:30
Scalar XZ
Definition: internals.h:30
Scalar YY
Definition: internals.h:64
SymmMat3x3Coefficients(const MatrixBase< D > &E)
Definition: internals.h:77
Scalar XY
Definition: internals.h:30
Scalar ZY
Definition: internals.h:30
Definition: rbd.h:173
Scalar ZZ
Definition: internals.h:30
void write(const MatrixBase< D > &Econst)
Definition: internals.h:89