Fix geom::shortest_arc in case of 180 degree rotation
This commit is contained in:
parent
d157ba1cd5
commit
3b509fb358
1 changed files with 9 additions and 2 deletions
|
|
@ -226,14 +226,21 @@ namespace psemek::geom
|
|||
|
||||
// v0 & v1 assumed to be normalized
|
||||
template <typename T>
|
||||
quaternion<T> shortest_arc(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
||||
quaternion<T> shortest_arc(vector<T, 3> const & v0, vector<T, 3> const & v1, T const eps = T{1e-6})
|
||||
{
|
||||
auto axis = cross(v0, v1);
|
||||
auto d = dot(v0, v1);
|
||||
|
||||
if (d + T{1} < eps)
|
||||
axis = ort(v0);
|
||||
|
||||
quaternion<T> result;
|
||||
|
||||
result[0] = axis[0];
|
||||
result[1] = axis[1];
|
||||
result[2] = axis[2];
|
||||
result[3] = T{1} + dot(v0, v1);
|
||||
result[3] = T{1} + d;
|
||||
|
||||
result.coords = normalized(result.coords);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue