Ignore:
Timestamp:
Jul 28, 2009, 1:01:15 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
3dc682
Parents:
78b45a
Message:

New function Vector::NormSquared() and Angle checks whether Norm's are unequal to zero.

  • New function Vector::NormSquared() calculates norm squared
  • Vector::Angle() checks whether the norms of the vectors are not zero, otherwise returning M_PI
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.cpp

    r78b45a rda5c7c  
    216216};
    217217
     218/** Calculates squared norm of this vector.
     219 * \return \f$|x|^2\f$
     220 */
     221double Vector::NormSquared() const
     222{
     223  return (ScalarProduct(this));
     224};
     225
    218226/** Normalizes this vector.
    219227 */
     
    259267double Vector::Angle(const Vector *y) const
    260268{
    261   double angle = this->ScalarProduct(y)/Norm()/y->Norm();
     269  double norm1 = Norm(), norm2 = y->Norm();
     270  double angle = 1;
     271  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
     272    angle = this->ScalarProduct(y)/norm1/norm2;
    262273  // -1-MYEPSILON occured due to numerical imprecision, catch ...
    263274  //cout << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl;
Note: See TracChangeset for help on using the changeset viewer.