BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_quaternion_rotate_vector.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_ROTATE_VECTOR_HPP
13
#define BELFEM_FN_QUATERNION_ROTATE_VECTOR_HPP
14
15
#include "
cl_Quaternion.hpp
"
16
#include "
cl_Vector.hpp
"
17
#include "
assert.hpp
"
18
19
namespace
belfem
20
{
21
//------------------------------------------------------------------------------
22
35
template
<
typename
T >
36
void
37
quaternion_rotate_vector
(
38
const
Quaternion < T > & aQ,
39
const
Vector < T > & aVector,
40
Vector < T > & aResult )
41
{
42
BELFEM_ASSERT
( std::abs( aQ.
norm
() - T( 1 ) ) < T( 100 ) *
BELFEM_EPSILON
,
43
"Input must be a unit quaternion"
);
44
BELFEM_ASSERT
( aVector.
length
() == 3,
"Input vector must have length 3"
);
45
BELFEM_ASSERT
( aResult.
length
() == 3,
"Output vector must have length 3"
);
46
47
T w = aQ.
a
();
48
T ux = aQ.
b
();
49
T uy = aQ.
c
();
50
T uz = aQ.
d
();
51
52
T vx = aVector( 0 );
53
T vy = aVector( 1 );
54
T vz = aVector( 2 );
55
56
// t = 2 * (u x v)
57
T tx = T( 2 ) * ( uy * vz - uz * vy );
58
T ty = T( 2 ) * ( uz * vx - ux * vz );
59
T tz = T( 2 ) * ( ux * vy - uy * vx );
60
61
// v' = v + w * t + u x t
62
aResult( 0 ) = vx + w * tx + ( uy * tz - uz * ty );
63
aResult( 1 ) = vy + w * ty + ( uz * tx - ux * tz );
64
aResult( 2 ) = vz + w * tz + ( ux * ty - uy * tx );
65
}
66
67
//------------------------------------------------------------------------------
68
}
69
#endif
//BELFEM_FN_QUATERNION_ROTATE_VECTOR_HPP
assert.hpp
BELFEM_ASSERT
#define BELFEM_ASSERT(aCheck,...)
Definition
assert.hpp:244
cl_Quaternion.hpp
cl_Vector.hpp
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::Vector::length
size_t length() const
get the length of the vector
Definition
cl_AR_Vector.hpp:257
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::quaternion_rotate_vector
void quaternion_rotate_vector(const Quaternion< T > &aQ, const Vector< T > &aVector, Vector< T > &aResult)
Rotate a 3D vector by a unit quaternion (optimized, in-place).
Definition
fn_quaternion_rotate_vector.hpp:37
belfem::BELFEM_EPSILON
constexpr real BELFEM_EPSILON
Definition
typedefs.hpp:90
src
math
quaternion
fn_quaternion_rotate_vector.hpp
Generated by
1.18.0