/** \file vector.cpp * * Function implementations for the class vector. * */ #include "defs.hpp" #include "gslmatrix.hpp" #include "leastsquaremin.hpp" #include "memoryallocator.hpp" #include "vector.hpp" #include "Helpers/fast_functions.hpp" #include "Helpers/Assert.hpp" #include "Plane.hpp" #include "Exceptions/LinearDependenceException.hpp" #include #include #include #include /************************************ Functions for class vector ************************************/ /** Constructor of class vector. */ Vector::Vector() { x[0] = x[1] = x[2] = 0.; }; /** Constructor of class vector. */ Vector::Vector(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; }; /** * Copy constructor */ Vector::Vector(const Vector& src) { x[0] = src[0]; x[1] = src[1]; x[2] = src[2]; } /** * Assignment operator */ Vector& Vector::operator=(const Vector& src){ // check for self assignment if(&src!=this){ x[0] = src[0]; x[1] = src[1]; x[2] = src[2]; } return *this; } /** Desctructor of class vector. */ Vector::~Vector() {}; /** Calculates square of distance between this and another vector. * \param *y array to second vector * \return \f$| x - y |^2\f$ */ double Vector::DistanceSquared(const Vector * const y) const { double res = 0.; for (int i=NDIM;i--;) res += (x[i]-y->x[i])*(x[i]-y->x[i]); return (res); }; /** Calculates distance between this and another vector. * \param *y array to second vector * \return \f$| x - y |\f$ */ double Vector::Distance(const Vector * const y) const { double res = 0.; for (int i=NDIM;i--;) res += (x[i]-y->x[i])*(x[i]-y->x[i]); return (sqrt(res)); }; /** Calculates distance between this and another vector in a periodic cell. * \param *y array to second vector * \param *cell_size 6-dimensional array with (xx, xy, yy, xz, yz, zz) entries specifying the periodic cell * \return \f$| x - y |\f$ */ double Vector::PeriodicDistance(const Vector * const y, const double * const cell_size) const { double res = Distance(y), tmp, matrix[NDIM*NDIM]; Vector Shiftedy, TranslationVector; int N[NDIM]; matrix[0] = cell_size[0]; matrix[1] = cell_size[1]; matrix[2] = cell_size[3]; matrix[3] = cell_size[1]; matrix[4] = cell_size[2]; matrix[5] = cell_size[4]; matrix[6] = cell_size[3]; matrix[7] = cell_size[4]; matrix[8] = cell_size[5]; // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells for (N[0]=-1;N[0]<=1;N[0]++) for (N[1]=-1;N[1]<=1;N[1]++) for (N[2]=-1;N[2]<=1;N[2]++) { // create the translation vector TranslationVector.Zero(); for (int i=NDIM;i--;) TranslationVector.x[i] = (double)N[i]; TranslationVector.MatrixMultiplication(matrix); // add onto the original vector to compare with Shiftedy.CopyVector(y); Shiftedy.AddVector(&TranslationVector); // get distance and compare with minimum so far tmp = Distance(&Shiftedy); if (tmp < res) res = tmp; } return (res); }; /** Calculates distance between this and another vector in a periodic cell. * \param *y array to second vector * \param *cell_size 6-dimensional array with (xx, xy, yy, xz, yz, zz) entries specifying the periodic cell * \return \f$| x - y |^2\f$ */ double Vector::PeriodicDistanceSquared(const Vector * const y, const double * const cell_size) const { double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; Vector Shiftedy, TranslationVector; int N[NDIM]; matrix[0] = cell_size[0]; matrix[1] = cell_size[1]; matrix[2] = cell_size[3]; matrix[3] = cell_size[1]; matrix[4] = cell_size[2]; matrix[5] = cell_size[4]; matrix[6] = cell_size[3]; matrix[7] = cell_size[4]; matrix[8] = cell_size[5]; // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells for (N[0]=-1;N[0]<=1;N[0]++) for (N[1]=-1;N[1]<=1;N[1]++) for (N[2]=-1;N[2]<=1;N[2]++) { // create the translation vector TranslationVector.Zero(); for (int i=NDIM;i--;) TranslationVector.x[i] = (double)N[i]; TranslationVector.MatrixMultiplication(matrix); // add onto the original vector to compare with Shiftedy.CopyVector(y); Shiftedy.AddVector(&TranslationVector); // get distance and compare with minimum so far tmp = DistanceSquared(&Shiftedy); if (tmp < res) res = tmp; } return (res); }; /** Keeps the vector in a periodic cell, defined by the symmetric \a *matrix. * \param *out ofstream for debugging messages * Tries to translate a vector into each adjacent neighbouring cell. */ void Vector::KeepPeriodic(const double * const matrix) { // int N[NDIM]; // bool flag = false; //vector Shifted, TranslationVector; Vector TestVector; // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; // Log() << Verbose(2) << "Vector is: "; // Output(out); // Log() << Verbose(0) << endl; TestVector.CopyVector(this); TestVector.InverseMatrixMultiplication(matrix); for(int i=NDIM;i--;) { // correct periodically if (TestVector.x[i] < 0) { // get every coefficient into the interval [0,1) TestVector.x[i] += ceil(TestVector.x[i]); } else { TestVector.x[i] -= floor(TestVector.x[i]); } } TestVector.MatrixMultiplication(matrix); CopyVector(&TestVector); // Log() << Verbose(2) << "New corrected vector is: "; // Output(out); // Log() << Verbose(0) << endl; // Log() << Verbose(1) << "End of KeepPeriodic." << endl; }; /** Calculates scalar product between this and another vector. * \param *y array to second vector * \return \f$\langle x, y \rangle\f$ */ double Vector::ScalarProduct(const Vector * const y) const { double res = 0.; for (int i=NDIM;i--;) res += x[i]*y->x[i]; return (res); }; /** Calculates VectorProduct between this and another vector. * -# returns the Product in place of vector from which it was initiated * -# ATTENTION: Only three dim. * \param *y array to vector with which to calculate crossproduct * \return \f$ x \times y \f& */ void Vector::VectorProduct(const Vector * const y) { Vector tmp; tmp.x[0] = x[1]* (y->x[2]) - x[2]* (y->x[1]); tmp.x[1] = x[2]* (y->x[0]) - x[0]* (y->x[2]); tmp.x[2] = x[0]* (y->x[1]) - x[1]* (y->x[0]); this->CopyVector(&tmp); }; /** projects this vector onto plane defined by \a *y. * \param *y normal vector of plane * \return \f$\langle x, y \rangle\f$ */ void Vector::ProjectOntoPlane(const Vector * const y) { Vector tmp; tmp.CopyVector(y); tmp.Normalize(); tmp.Scale(ScalarProduct(&tmp)); this->SubtractVector(&tmp); }; /** Calculates the minimum distance of this vector to the plane. * \param *out output stream for debugging * \param *PlaneNormal normal of plane * \param *PlaneOffset offset of plane * \return distance to plane */ double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const { Vector temp; // first create part that is orthonormal to PlaneNormal with withdraw temp.CopyVector(this); temp.SubtractVector(PlaneOffset); temp.MakeNormalTo(*PlaneNormal); temp.Scale(-1.); // then add connecting vector from plane to point temp.AddVector(this); temp.SubtractVector(PlaneOffset); double sign = temp.ScalarProduct(PlaneNormal); if (fabs(sign) > MYEPSILON) sign /= fabs(sign); else sign = 0.; return (temp.Norm()*sign); }; /** Calculates the projection of a vector onto another \a *y. * \param *y array to second vector */ void Vector::ProjectIt(const Vector * const y) { Vector helper(*y); helper.Scale(-(ScalarProduct(y))); AddVector(&helper); }; /** Calculates the projection of a vector onto another \a *y. * \param *y array to second vector * \return Vector */ Vector Vector::Projection(const Vector * const y) const { Vector helper(*y); helper.Scale((ScalarProduct(y)/y->NormSquared())); return helper; }; /** Calculates norm of this vector. * \return \f$|x|\f$ */ double Vector::Norm() const { double res = 0.; for (int i=NDIM;i--;) res += this->x[i]*this->x[i]; return (sqrt(res)); }; /** Calculates squared norm of this vector. * \return \f$|x|^2\f$ */ double Vector::NormSquared() const { return (ScalarProduct(this)); }; /** Normalizes this vector. */ void Vector::Normalize() { double res = 0.; for (int i=NDIM;i--;) res += this->x[i]*this->x[i]; if (fabs(res) > MYEPSILON) res = 1./sqrt(res); Scale(&res); }; /** Zeros all components of this vector. */ void Vector::Zero() { for (int i=NDIM;i--;) this->x[i] = 0.; }; /** Zeros all components of this vector. */ void Vector::One(const double one) { for (int i=NDIM;i--;) this->x[i] = one; }; /** Initialises all components of this vector. */ void Vector::Init(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; }; /** Checks whether vector has all components zero. * @return true - vector is zero, false - vector is not */ bool Vector::IsZero() const { return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON); }; /** Checks whether vector has length of 1. * @return true - vector is normalized, false - vector is not */ bool Vector::IsOne() const { return (fabs(Norm() - 1.) < MYEPSILON); }; /** Checks whether vector is normal to \a *normal. * @return true - vector is normalized, false - vector is not */ bool Vector::IsNormalTo(const Vector * const normal) const { if (ScalarProduct(normal) < MYEPSILON) return true; else return false; }; /** Checks whether vector is normal to \a *normal. * @return true - vector is normalized, false - vector is not */ bool Vector::IsEqualTo(const Vector * const a) const { bool status = true; for (int i=0;ix[i]) > MYEPSILON) status = false; } return status; }; /** Calculates the angle between this and another vector. * \param *y array to second vector * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$ */ double Vector::Angle(const Vector * const y) const { double norm1 = Norm(), norm2 = y->Norm(); double angle = -1; if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) angle = this->ScalarProduct(y)/norm1/norm2; // -1-MYEPSILON occured due to numerical imprecision, catch ... //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl; if (angle < -1) angle = -1; if (angle > 1) angle = 1; return acos(angle); }; double& Vector::operator[](size_t i){ ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); return x[i]; } const double& Vector::operator[](size_t i) const{ ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); return x[i]; } double& Vector::at(size_t i){ return (*this)[i]; } const double& Vector::at(size_t i) const{ return (*this)[i]; } double* Vector::get(){ return x; } /** Compares vector \a to vector \a b component-wise. * \param a base vector * \param b vector components to add * \return a == b */ bool operator==(const Vector& a, const Vector& b) { bool status = true; for (int i=0;ix[i]; }; /** Given a box by its matrix \a *M and its inverse *Minv the vector is made to point within that box. * \param *M matrix of box * \param *Minv inverse matrix */ void Vector::WrapPeriodically(const double * const M, const double * const Minv) { MatrixMultiplication(Minv); // truncate to [0,1] for each axis for (int i=0;i= 1.) x[i] -= 1.; while (x[i] < 0.) x[i] += 1.; } MatrixMultiplication(M); }; /** Do a matrix multiplication. * \param *matrix NDIM_NDIM array */ void Vector::MatrixMultiplication(const double * const M) { Vector C; // do the matrix multiplication C.x[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; C.x[1] = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; C.x[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; // transfer the result into this for (int i=NDIM;i--;) x[i] = C.x[i]; }; /** Do a matrix multiplication with the \a *A' inverse. * \param *matrix NDIM_NDIM array */ bool Vector::InverseMatrixMultiplication(const double * const A) { Vector C; double B[NDIM*NDIM]; double detA = RDET3(A); double detAReci; // calculate the inverse B if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular detAReci = 1./detA; B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 // do the matrix multiplication C.x[0] = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; C.x[1] = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; C.x[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; // transfer the result into this for (int i=NDIM;i--;) x[i] = C.x[i]; return true; } else { return false; } }; /** Creates this vector as the b y *factors' components scaled linear combination of the given three. * this vector = x1*factors[0] + x2* factors[1] + x3*factors[2] * \param *x1 first vector * \param *x2 second vector * \param *x3 third vector * \param *factors three-component vector with the factor for each given vector */ void Vector::LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors) { for(int i=NDIM;i--;) x[i] = factors[0]*x1->x[i] + factors[1]*x2->x[i] + factors[2]*x3->x[i]; }; /** Mirrors atom against a given plane. * \param n[] normal vector of mirror plane. */ void Vector::Mirror(const Vector * const n) { double projection; projection = ScalarProduct(n)/n->ScalarProduct(n); // remove constancy from n (keep as logical one) // withdraw projected vector twice from original one for (int i=NDIM;i--;) x[i] -= 2.*projection*n->x[i]; }; /** Calculates orthonormal vector to one given vector. * Just subtracts the projection onto the given vector from this vector. * The removed part of the vector is Vector::Projection() * \param *x1 vector * \return true - success, false - vector is zero */ bool Vector::MakeNormalTo(const Vector &y1) { bool result = false; double factor = y1.ScalarProduct(this)/y1.NormSquared(); Vector x1; x1.CopyVector(&y1); x1.Scale(factor); SubtractVector(&x1); for (int i=NDIM;i--;) result = result || (fabs(x[i]) > MYEPSILON); return result; }; /** Creates this vector as one of the possible orthonormal ones to the given one. * Just scan how many components of given *vector are unequal to zero and * try to get the skp of both to be zero accordingly. * \param *vector given vector * \return true - success, false - failure (null vector given) */ bool Vector::GetOneNormalVector(const Vector * const GivenVector) { int Components[NDIM]; // contains indices of non-zero components int Last = 0; // count the number of non-zero entries in vector int j; // loop variables double norm; for (j=NDIM;j--;) Components[j] = -1; // find two components != 0 for (j=0;jx[j]) > MYEPSILON) Components[Last++] = j; switch(Last) { case 3: // threecomponent system case 2: // two component system norm = sqrt(1./(GivenVector->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]])); x[Components[2]] = 0.; // in skp both remaining parts shall become zero but with opposite sign and third is zero x[Components[1]] = -1./GivenVector->x[Components[1]] / norm; x[Components[0]] = 1./GivenVector->x[Components[0]] / norm; return true; break; case 1: // one component system // set sole non-zero component to 0, and one of the other zero component pendants to 1 x[(Components[0]+2)%NDIM] = 0.; x[(Components[0]+1)%NDIM] = 1.; x[Components[0]] = 0.; return true; break; default: return false; } }; /** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C. * \param *A first plane vector * \param *B second plane vector * \param *C third plane vector * \return scaling parameter for this vector */ double Vector::CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const { // Log() << Verbose(3) << "For comparison: "; // Log() << Verbose(0) << "A " << A->Projection(this) << "\t"; // Log() << Verbose(0) << "B " << B->Projection(this) << "\t"; // Log() << Verbose(0) << "C " << C->Projection(this) << "\t"; // Log() << Verbose(0) << endl; return A->ScalarProduct(this); }; /** Adds vector \a *y componentwise. * \param *y vector */ void Vector::AddVector(const Vector * const y) { for (int i=NDIM;i--;) this->x[i] += y->x[i]; } /** Adds vector \a *y componentwise. * \param *y vector */ void Vector::SubtractVector(const Vector * const y) { for (int i=NDIM;i--;) this->x[i] -= y->x[i]; } /** Copy vector \a *y componentwise. * \param *y vector */ void Vector::CopyVector(const Vector * const y) { // check for self assignment if(y!=this){ for (int i=NDIM;i--;) this->x[i] = y->x[i]; } } /** Copy vector \a y componentwise. * \param y vector */ void Vector::CopyVector(const Vector &y) { // check for self assignment if(&y!=this) { for (int i=NDIM;i--;) this->x[i] = y.x[i]; } } // this function is completely unused so it is deactivated until new uses arrive and a new // place can be found #if 0 /** Solves a vectorial system consisting of two orthogonal statements and a norm statement. * This is linear system of equations to be solved, however of the three given (skp of this vector\ * with either of the three hast to be zero) only two are linear independent. The third equation * is that the vector should be of magnitude 1 (orthonormal). This all leads to a case-based solution * where very often it has to be checked whether a certain value is zero or not and thus forked into * another case. * \param *x1 first vector * \param *x2 second vector * \param *y third vector * \param alpha first angle * \param beta second angle * \param c norm of final vector * \return a vector with \f$\langle x1,x2 \rangle=A\f$, \f$\langle x1,y \rangle = B\f$ and with norm \a c. * \bug this is not yet working properly */ bool Vector::SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c) { double D1,D2,D3,E1,E2,F1,F2,F3,p,q=0., A, B1, B2, C; double ang; // angle on testing double sign[3]; int i,j,k; A = cos(alpha) * x1->Norm() * c; B1 = cos(beta + M_PI/2.) * y->Norm() * c; B2 = cos(beta) * x2->Norm() * c; C = c * c; Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl; int flag = 0; if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping if (fabs(x1->x[1]) > MYEPSILON) { flag = 1; } else if (fabs(x1->x[2]) > MYEPSILON) { flag = 2; } else { return false; } } switch (flag) { default: case 0: break; case 2: flip(x1->x[0],x1->x[1]); flip(x2->x[0],x2->x[1]); flip(y->x[0],y->x[1]); //flip(x[0],x[1]); flip(x1->x[1],x1->x[2]); flip(x2->x[1],x2->x[2]); flip(y->x[1],y->x[2]); //flip(x[1],x[2]); case 1: flip(x1->x[0],x1->x[1]); flip(x2->x[0],x2->x[1]); flip(y->x[0],y->x[1]); //flip(x[0],x[1]); flip(x1->x[1],x1->x[2]); flip(x2->x[1],x2->x[2]); flip(y->x[1],y->x[2]); //flip(x[1],x[2]); break; } // now comes the case system D1 = -y->x[0]/x1->x[0]*x1->x[1]+y->x[1]; D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2]; D3 = y->x[0]/x1->x[0]*A-B1; Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n"; if (fabs(D1) < MYEPSILON) { Log() << Verbose(2) << "D1 == 0!\n"; if (fabs(D2) > MYEPSILON) { Log() << Verbose(3) << "D2 != 0!\n"; x[2] = -D3/D2; E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2; E2 = -x1->x[1]/x1->x[0]; Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n"; F1 = E1*E1 + 1.; F2 = -E1*E2; F3 = E1*E1 + D3*D3/(D2*D2) - C; Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"; if (fabs(F1) < MYEPSILON) { Log() << Verbose(4) << "F1 == 0!\n"; Log() << Verbose(4) << "Gleichungssystem linear\n"; x[1] = F3/(2.*F2); } else { p = F2/F1; q = p*p - F3/F1; Log() << Verbose(4) << "p " << p << "\tq " << q << endl; if (q < 0) { Log() << Verbose(4) << "q < 0" << endl; return false; } x[1] = p + sqrt(q); } x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; } else { Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n"; return false; } } else { E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1; E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2]; Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n"; F1 = E2*E2 + D2*D2/(D1*D1) + 1.; F2 = -(E1*E2 + D2*D3/(D1*D1)); F3 = E1*E1 + D3*D3/(D1*D1) - C; Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"; if (fabs(F1) < MYEPSILON) { Log() << Verbose(3) << "F1 == 0!\n"; Log() << Verbose(3) << "Gleichungssystem linear\n"; x[2] = F3/(2.*F2); } else { p = F2/F1; q = p*p - F3/F1; Log() << Verbose(3) << "p " << p << "\tq " << q << endl; if (q < 0) { Log() << Verbose(3) << "q < 0" << endl; return false; } x[2] = p + sqrt(q); } x[1] = (-D2 * x[2] - D3)/D1; x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; } switch (flag) { // back-flipping default: case 0: break; case 2: flip(x1->x[0],x1->x[1]); flip(x2->x[0],x2->x[1]); flip(y->x[0],y->x[1]); flip(x[0],x[1]); flip(x1->x[1],x1->x[2]); flip(x2->x[1],x2->x[2]); flip(y->x[1],y->x[2]); flip(x[1],x[2]); case 1: flip(x1->x[0],x1->x[1]); flip(x2->x[0],x2->x[1]); flip(y->x[0],y->x[1]); //flip(x[0],x[1]); flip(x1->x[1],x1->x[2]); flip(x2->x[1],x2->x[2]); flip(y->x[1],y->x[2]); flip(x[1],x[2]); break; } // one z component is only determined by its radius (without sign) // thus check eight possible sign flips and determine by checking angle with second vector for (i=0;i<8;i++) { // set sign vector accordingly for (j=2;j>=0;j--) { k = (i & pot(2,j)) << j; Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl; sign[j] = (k == 0) ? 1. : -1.; } Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n"; // apply sign matrix for (j=NDIM;j--;) x[j] *= sign[j]; // calculate angle and check ang = x2->Angle (this); Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t"; if (fabs(ang - cos(beta)) < MYEPSILON) { break; } // unapply sign matrix (is its own inverse) for (j=NDIM;j--;) x[j] *= sign[j]; } return true; }; #endif /** * Checks whether this vector is within the parallelepiped defined by the given three vectors and * their offset. * * @param offest for the origin of the parallelepiped * @param three vectors forming the matrix that defines the shape of the parallelpiped */ bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const { Vector a; a.CopyVector(this); a.SubtractVector(&offset); a.InverseMatrixMultiplication(parallelepiped); bool isInside = true; for (int i=NDIM;i--;) isInside = isInside && ((a.x[i] <= 1) && (a.x[i] >= 0)); return isInside; }