Add geom::shortest_arc to compute smallest rotation between two 3D vectors
This commit is contained in:
parent
d405d3d502
commit
11c431f38c
1 changed files with 14 additions and 0 deletions
|
|
@ -224,6 +224,20 @@ namespace psemek::geom
|
|||
return {res[0], res[1], res[2]};
|
||||
}
|
||||
|
||||
// v0 & v1 assumed to be normalized
|
||||
template <typename T>
|
||||
quaternion<T> shortest_arc(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
||||
{
|
||||
auto axis = cross(v0, v1);
|
||||
quaternion<T> result;
|
||||
result[0] = axis[0];
|
||||
result[1] = axis[1];
|
||||
result[2] = axis[2];
|
||||
result[3] = T{1} + dot(v0, v1);
|
||||
result.coords = normalized(result.coords);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T angle(quaternion<T> const & q0, quaternion<T> const & q1)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue