28#ifndef GEOMETRIC_OPERATIONS_H
29#define GEOMETRIC_OPERATIONS_H
40template <
typename T,
unsigned D>
45 return conversionFactor * angle;
54template <
typename T,
unsigned D>
59 return conversionFactor * angle;
68template <
typename T,
unsigned D>
74 if constexpr (D == 2) {
79 rotationMatrix[0] =
cos;
80 rotationMatrix[1] = -
sin;
82 rotationMatrix[2] =
sin;
83 rotationMatrix[3] =
cos;
96 rotationMatrix[0] =
cos[1] *
cos[2];
100 rotationMatrix[3] =
cos[1] *
sin[2];
104 rotationMatrix[6] = -
sin[1];
105 rotationMatrix[7] =
sin[0] *
cos[1];
106 rotationMatrix[8] =
cos[0] *
cos[1];
109 return rotationMatrix;
120 return Vector{m[0], m[3], m[6],
126template <
typename T,
unsigned D>
133 for (
unsigned jD=0; jD < D; ++jD) {
134 element += M[iD*D + jD] * b[jD];
141template <
typename T,
unsigned D>
147 for (
unsigned i=0; i < D; ++i) {
148 for (
unsigned j=0; j < D; ++j) {
149 for (
unsigned k=0; k < D; ++k) {
150 C[i*D + j] += A[i*D + k] * B[k*D + j];
157template <
typename T,
unsigned D>
161 if constexpr (D == 2) {
162 return Vector<T, 4>(rotationMatrix[0], rotationMatrix[2], rotationMatrix[1],
172 return Vector<T, 9>(rotationMatrix[0], rotationMatrix[3], rotationMatrix[6],
173 rotationMatrix[1], rotationMatrix[4], rotationMatrix[7],
174 rotationMatrix[2], rotationMatrix[5],
177 __builtin_unreachable();
180template <
typename T,
unsigned D>
189template <
typename T,
unsigned D,
190 bool OUTPUT_USES_ROTATION_CENTER_AS_ORIGIN =
false>
199 if constexpr (D == 2) {
201 Vector<T, 2>(dist[0] * rotationMatrix[0] + dist[1] * rotationMatrix[1],
202 dist[0] * rotationMatrix[2] + dist[1] * rotationMatrix[3]);
206 Vector<T, 3>(rotationMatrix[0] * dist[0] + rotationMatrix[1] * dist[1] +
207 rotationMatrix[2] * dist[2],
208 rotationMatrix[3] * dist[0] + rotationMatrix[4] * dist[1] +
209 rotationMatrix[5] * dist[2],
210 rotationMatrix[6] * dist[0] + rotationMatrix[7] * dist[1] +
211 rotationMatrix[8] * dist[2]);
214 if constexpr (!OUTPUT_USES_ROTATION_CENTER_AS_ORIGIN) {
215 return rotationCenter + rotated;
221 __builtin_unreachable();
225template <
typename T,
unsigned D,
226 bool OUTPUT_USES_ROTATION_CENTER_AS_ORIGIN =
false>
238template <
typename T,
unsigned D>
245 if constexpr (D == 2) {
248 velocity[0] - angularVelocity[0] * (position[1] - rotationCenter[1]),
249 velocity[1] + angularVelocity[0] * (position[0] - rotationCenter[0]));
256 __builtin_unreachable();
267 {mofi[0], T {}, T {}},
268 { T {}, mofi[1], T {}},
269 { T {}, T {}, mofi[2]}
274 _rotationMatrix * inertiaTensor * (_rotationMatrix.
transpose());
276 return inertiaTensor;
Matrix with a defined number of ROWS and columns (COLS)
constexpr Matrix< T, COLS, ROWS > transpose() const
decltype(Vector< decltype(util::sqrt(T())), D >()) radianToDegree(const Vector< T, D > &angle)
Vector< T, D > invertRotation(const Vector< T, D > &input, const Vector< T, utilities::dimensions::convert< D >::matrix > &rotationMatrix, const Vector< T, D > &rotationCenter=Vector< T, D >(0.))
Rotates the input around the rotationCenter with a given rotationMatrix in the opposite direction.
Vector< T, utilities::dimensions::convert< D >::matrix > matrixMatrixProduct(const Vector< T, utilities::dimensions::convert< D >::matrix > &A, const Vector< T, utilities::dimensions::convert< D >::matrix > &B) any_platform
Compute C=AB for square matrices.
constexpr Matrix< T, 3, 3 > rotateMofi(const Vector< T, 3 > &mofi, const Vector< T, 9 > &rotationMatrix)
Rotate moment of inertia (mofi)
ADf< T, DIM > sin(const ADf< T, DIM > &a)
decltype(Vector< decltype(util::sqrt(T())), D >()) degreeToRadian(const Vector< T, D > &angle)
Vector< T, D > executeRotation(const Vector< T, D > &input, const Vector< T, utilities::dimensions::convert< D >::matrix > &rotationMatrix, const Vector< T, D > &rotationCenter=Vector< T, D >(0.))
Rotates the input around the rotationCenter with a given rotationMatrix.
Vector< T, utilities::dimensions::convert< D >::matrix > calculateRotationMatrix(const Vector< T, utilities::dimensions::convert< D >::rotation > &angle) any_platform
constexpr Vector< T, D > calculateLocalVelocity(const Vector< T, D > &rotationCenter, const Vector< T, D > &velocity, const Vector< T, utilities::dimensions::convert< D >::rotation > &angularVelocity, const Vector< T, D > &position)
Calculate local velocity.
Vector< T, 4 > inverseRotation(const Vector< T, 4 > &m) any_platform
Vector< T, D > matrixVectorProduct(const Vector< T, utilities::dimensions::convert< D >::matrix > &M, const Vector< T, D > &b) any_platform
Compute v=M b.
Vector< T, utilities::dimensions::convert< D >::matrix > invertRotationMatrix(const Vector< T, utilities::dimensions::convert< D >::matrix > &rotationMatrix)
Vector< T, utilities::dimensions::convert< D >::matrix > calculateInverseRotationMatrix(const Vector< T, utilities::dimensions::convert< D >::rotation > &angle)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>
typename util::BaseTypeHelper< T >::type BaseType
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
Converts dimensions by deriving from given cartesian dimension D.
efficient implementation of a vector class