Use faster quaternion rotation formula
This commit is contained in:
parent
540d63ce5b
commit
84ef3faa68
1 changed files with 4 additions and 2 deletions
|
|
@ -213,8 +213,10 @@ namespace psemek::geom
|
|||
template <typename T>
|
||||
vector<T, 3> rotate(quaternion<T> const & q, vector<T, 3> const & v)
|
||||
{
|
||||
auto res = q * quaternion<T>::vector(v) * conjugate(q);
|
||||
return {res[0], res[1], res[2]};
|
||||
// 2x faster than q*v*cong(q), see https://www.johndcook.com/blog/2021/06/16/faster-quaternion-rotations/
|
||||
auto qv = vector{q[0], q[1], q[2]};
|
||||
auto t = T(2) * cross(qv, v);
|
||||
return v + q[3] * t + cross(qv, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue