bugfix rotation from between 2 vectors

This commit is contained in:
Luigi Malomo 2021-05-07 17:25:34 +02:00
parent e165cc4e45
commit 290ac7a027
1 changed files with 5 additions and 5 deletions

View File

@ -523,7 +523,7 @@ Matrix33<S> RotationMatrix(vcg::Point3<S> v0,vcg::Point3<S> v1,bool normalized=t
} }
S dot=(v0*v1); S dot=(v0*v1);
///control if there is no rotation ///control if there is no rotation
if (dot>((S)1-epsilon)) if (dot>(S(1)-epsilon))
{ {
rotM.SetIdentity(); rotM.SetIdentity();
return rotM; return rotM;
@ -535,13 +535,13 @@ Matrix33<S> RotationMatrix(vcg::Point3<S> v0,vcg::Point3<S> v1,bool normalized=t
//if dot = -1 rotating to opposite vertex //if dot = -1 rotating to opposite vertex
//the problem is underdefined, so choose axis such that division is more stable //the problem is underdefined, so choose axis such that division is more stable
//alternative solution at http://cs.brown.edu/research/pubs/pdfs/1999/Moller-1999-EBA.pdf //alternative solution at http://cs.brown.edu/research/pubs/pdfs/1999/Moller-1999-EBA.pdf
if (dot < (S)-1 + epsilon) if (dot < S(-1) + epsilon)
{ {
S max = std::numeric_limits<S>::min(); S max = std::numeric_limits<S>::lowest();
int maxInd = 0; int maxInd = 0;
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
if (v0[i] > max) if (std::abs(v0[i]) > max)
{ {
max = v0[i]; max = v0[i];
maxInd = i; maxInd = i;
@ -552,7 +552,7 @@ Matrix33<S> RotationMatrix(vcg::Point3<S> v0,vcg::Point3<S> v1,bool normalized=t
axis[(maxInd+1) % 3] = 0; axis[(maxInd+1) % 3] = 0;
axis[(maxInd+2) % 3] = 1; axis[(maxInd+2) % 3] = 1;
dot = (S)-1; dot = S(-1);
} }
else else
{ {