BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_quaternion_to_rotation_matrix.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California,
4
* through Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
12
#ifndef BELFEM_FN_QUATERNION_TO_ROTATION_MATRIX_HPP
13
#define BELFEM_FN_QUATERNION_TO_ROTATION_MATRIX_HPP
14
15
#include "
cl_Quaternion.hpp
"
16
#include "
cl_Matrix.hpp
"
17
#include "
assert.hpp
"
18
19
namespace
belfem
20
{
21
//------------------------------------------------------------------------------
22
35
template
<
typename
T >
36
void
37
quaternion_to_rotation_matrix
(
38
const
Quaternion < T > & aQ,
39
Matrix < T > & aMatrix )
40
{
41
BELFEM_ASSERT
( aMatrix.
n_rows
() == 3 && aMatrix.
n_cols
() == 3,
42
"Output matrix must be 3x3"
);
43
44
BELFEM_ASSERT
( std::abs( aQ.
norm
() - T( 1 ) ) < T( 100 ) *
BELFEM_EPSILON
,
45
"Input must be a unit quaternion"
);
46
47
T w = aQ.
a
();
48
T x = aQ.
b
();
49
T y = aQ.
c
();
50
T z = aQ.
d
();
51
52
T xx = x * x;
53
T yy = y * y;
54
T zz = z * z;
55
T xy = x * y;
56
T xz = x * z;
57
T yz = y * z;
58
T wx = w * x;
59
T wy = w * y;
60
T wz = w * z;
61
62
aMatrix( 0, 0 ) = T( 1 ) - T( 2 ) * ( yy + zz );
63
aMatrix( 0, 1 ) = T( 2 ) * ( xy - wz );
64
aMatrix( 0, 2 ) = T( 2 ) * ( xz + wy );
65
66
aMatrix( 1, 0 ) = T( 2 ) * ( xy + wz );
67
aMatrix( 1, 1 ) = T( 1 ) - T( 2 ) * ( xx + zz );
68
aMatrix( 1, 2 ) = T( 2 ) * ( yz - wx );
69
70
aMatrix( 2, 0 ) = T( 2 ) * ( xz - wy );
71
aMatrix( 2, 1 ) = T( 2 ) * ( yz + wx );
72
aMatrix( 2, 2 ) = T( 1 ) - T( 2 ) * ( xx + yy );
73
}
74
75
//------------------------------------------------------------------------------
76
}
77
#endif
//BELFEM_FN_QUATERNION_TO_ROTATION_MATRIX_HPP
assert.hpp
BELFEM_ASSERT
#define BELFEM_ASSERT(aCheck,...)
Definition
assert.hpp:244
cl_Matrix.hpp
cl_Quaternion.hpp
belfem::Matrix::n_rows
size_t n_rows() const
Definition
cl_AR_Matrix.hpp:205
belfem::Matrix::n_cols
size_t n_cols() const
Definition
cl_AR_Matrix.hpp:213
belfem::Quaternion::a
T & a()
Definition
cl_Quaternion.hpp:110
belfem::Quaternion::d
T & d()
Definition
cl_Quaternion.hpp:140
belfem::Quaternion::c
T & c()
Definition
cl_Quaternion.hpp:130
belfem::Quaternion::b
T & b()
Definition
cl_Quaternion.hpp:120
belfem::Quaternion::norm
T norm() const
Definition
cl_Quaternion.hpp:249
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::quaternion_to_rotation_matrix
void quaternion_to_rotation_matrix(const Quaternion< T > &aQ, Matrix< T > &aMatrix)
Convert a unit quaternion to a 3x3 rotation matrix.
Definition
fn_quaternion_to_rotation_matrix.hpp:37
belfem::BELFEM_EPSILON
constexpr real BELFEM_EPSILON
Definition
typedefs.hpp:90
src
math
quaternion
fn_quaternion_to_rotation_matrix.hpp
Generated by
1.18.0