Changeset 54de04 for molecuilder/src


Ignore:
Timestamp:
Jul 7, 2009, 8:12:28 AM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
d98327
Parents:
eeae5b
Message:

BUGFIX: Numerical imprecision forced check of bounds for acos()

Scalarproduct(a)/Norm()/a.Norm() may result in values larger than 1 and smaller than -1 due to numerical rounding errors. -1-MYEPSILON causes NaN to be returned by acos, hence we check whether the value is smaller than -1 or greater than 1 and set to the limit if out of bounds.

This causes a wrong triangle to be taken due to the wrong SphereCenter being copied (comparing MYEPSILON to NAN)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.cpp

    reeae5b r54de04  
    259259double Vector::Angle(const Vector *y) const
    260260{
    261         return acos(this->ScalarProduct(y)/Norm()/y->Norm());
     261  double angle = this->ScalarProduct(y)/Norm()/y->Norm();
     262  // -1-MYEPSILON occured due to numerical imprecision, catch ...
     263  //cout << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl;
     264  if (angle < -1)
     265    angle = -1;
     266  if (angle > 1)
     267    angle = 1;
     268        return acos(angle);
    262269};
    263270
Note: See TracChangeset for help on using the changeset viewer.