Add geom::log(quaternion)
This commit is contained in:
parent
ae4ee3488a
commit
23551f681d
1 changed files with 15 additions and 0 deletions
|
|
@ -246,6 +246,21 @@ namespace psemek::geom
|
|||
return std::exp(q[3]) * quaternion<T>({v[0] * s, v[1] * s, v[2] * s, std::cos(l)});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
quaternion<T> log(quaternion<T> const & q)
|
||||
{
|
||||
auto v = vector{q[0], q[1], q[2]};
|
||||
auto l = length(v);
|
||||
auto n = length(q);
|
||||
|
||||
if (l == T{})
|
||||
v = v.zero();
|
||||
else
|
||||
v = (v / l) * std::acos(q[3] / n);
|
||||
|
||||
return quaternion<T>{{v[0], v[1], v[2], std::log(n)}};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream & operator << (std::ostream & os, quaternion<T> const & q)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue