Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/vector.cpp

    r7b36fe ra67d19  
    1515#include "vector.hpp"
    1616#include "verbose.hpp"
     17#include "World.hpp"
    1718
    1819#include <gsl/gsl_linalg.h>
     
    2627 */
    2728Vector::Vector() { x[0] = x[1] = x[2] = 0.; };
     29
     30/** Constructor of class vector.
     31 */
     32Vector::Vector(const Vector * const a)
     33{
     34  x[0] = a->x[0];
     35  x[1] = a->x[1];
     36  x[2] = a->x[2];
     37};
     38
     39/** Constructor of class vector.
     40 */
     41Vector::Vector(const Vector &a)
     42{
     43  x[0] = a.x[0];
     44  x[1] = a.x[1];
     45  x[2] = a.x[2];
     46};
    2847
    2948/** Constructor of class vector.
     
    234253  Direction.SubtractVector(Origin);
    235254  Direction.Normalize();
    236   Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl;
     255  DoLog(1) && (Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl);
    237256  //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl;
    238257  factor = Direction.ScalarProduct(PlaneNormal);
    239258  if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane?
    240     Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl;
     259    DoLog(1) && (Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl);
    241260    return false;
    242261  }
     
    245264  factor = helper.ScalarProduct(PlaneNormal)/factor;
    246265  if (fabs(factor) < MYEPSILON) { // Origin is in-plane
    247     Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl;
     266    DoLog(1) && (Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl);
    248267    CopyVector(Origin);
    249268    return true;
     
    252271  Direction.Scale(factor);
    253272  CopyVector(Origin);
    254   Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl;
     273  DoLog(1) && (Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl);
    255274  AddVector(&Direction);
    256275
     
    259278  helper.SubtractVector(PlaneOffset);
    260279  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    261     Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl;
     280    DoLog(1) && (Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl);
    262281    return true;
    263282  } else {
    264     eLog() << Verbose(2) << "Intersection point " << *this << " is not on plane." << endl;
     283    DoeLog(2) && (eLog()<< Verbose(2) << "Intersection point " << *this << " is not on plane." << endl);
    265284    return false;
    266285  }
    267286};
    268287
    269 /** Calculates the minimum distance of this vector to the plane.
     288/** Calculates the minimum distance vector of this vector to the plane.
    270289 * \param *out output stream for debugging
    271290 * \param *PlaneNormal normal of plane
    272291 * \param *PlaneOffset offset of plane
    273  * \return distance to plane
    274  */
    275 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
     292 * \return distance vector onto to plane
     293 */
     294Vector Vector::GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
    276295{
    277296  Vector temp;
     
    291310    sign = 0.;
    292311
    293   return (temp.Norm()*sign);
     312  temp.Normalize();
     313  temp.Scale(sign);
     314  return temp;
     315};
     316
     317/** Calculates the minimum distance of this vector to the plane.
     318 * \sa Vector::GetDistanceVectorToPlane()
     319 * \param *out output stream for debugging
     320 * \param *PlaneNormal normal of plane
     321 * \param *PlaneOffset offset of plane
     322 * \return distance to plane
     323 */
     324double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
     325{
     326  return GetDistanceVectorToPlane(PlaneNormal,PlaneOffset).Norm();
    294327};
    295328
     
    319352 
    320353  //Log() << Verbose(1) << "Coefficent matrix is:" << endl;
     354  //ostream &output = Log() << Verbose(1);
    321355  //for (int i=0;i<4;i++) {
    322356  //  for (int j=0;j<4;j++)
    323   //    cout << "\t" << M->Get(i,j);
    324   //  cout << endl;
     357  //    output << "\t" << M->Get(i,j);
     358  //  output << endl;
    325359  //}
    326360  if (fabs(M->Determinant()) > MYEPSILON) {
    327     Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;
     361    DoLog(1) && (Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl);
    328362    return false;
    329363  }
    330   Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl;
     364  DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl);
    331365
    332366
     
    344378  d.CopyVector(Line2b);
    345379  d.SubtractVector(Line1b);
    346   Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;
     380  DoLog(1) && (Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl);
    347381  if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {
    348382   Zero();
    349    Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;
     383   DoLog(1) && (Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl);
    350384   return false;
    351385  }
     
    360394    if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    361395      CopyVector(Line2a);
    362       Log() << Verbose(1) << "Lines conincide." << endl;
     396      DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
    363397      return true;
    364398    } else {
     
    368402      if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    369403        CopyVector(Line2b);
    370         Log() << Verbose(1) << "Lines conincide." << endl;
     404        DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
    371405        return true;
    372406      }
    373407    }
    374     Log() << Verbose(1) << "Lines are parallel." << endl;
     408    DoLog(1) && (Log() << Verbose(1) << "Lines are parallel." << endl);
    375409    Zero();
    376410    return false;
     
    384418  temp2.CopyVector(&a);
    385419  temp2.VectorProduct(&b);
    386   Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;
     420  DoLog(1) && (Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl);
    387421  if (fabs(temp2.NormSquared()) > MYEPSILON)
    388422    s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();
    389423  else
    390424    s = 0.;
    391   Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;
     425  DoLog(1) && (Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl);
    392426
    393427  // construct intersection
     
    395429  Scale(s);
    396430  AddVector(Line1a);
    397   Log() << Verbose(1) << "Intersection is at " << *this << "." << endl;
     431  DoLog(1) && (Log() << Verbose(1) << "Intersection is at " << *this << "." << endl);
    398432
    399433  return true;
     
    668702void Vector::Output() const
    669703{
    670   Log() << Verbose(0) << "(";
     704  DoLog(0) && (Log() << Verbose(0) << "(");
    671705  for (int i=0;i<NDIM;i++) {
    672     Log() << Verbose(0) << x[i];
     706    DoLog(0) && (Log() << Verbose(0) << x[i]);
    673707    if (i != 2)
    674       Log() << Verbose(0) << ",";
    675   }
    676   Log() << Verbose(0) << ")";
     708      DoLog(0) && (Log() << Verbose(0) << ",");
     709  }
     710  DoLog(0) && (Log() << Verbose(0) << ")");
    677711};
    678712
     
    783817      x[i] = C.x[i];
    784818  } else {
    785     eLog() << Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl;
     819    DoeLog(1) && (eLog()<< Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl);
    786820  }
    787821};
     
    809843  projection = ScalarProduct(n)/n->ScalarProduct(n);    // remove constancy from n (keep as logical one)
    810844  // withdraw projected vector twice from original one
    811   Log() << Verbose(1) << "Vector: ";
     845  DoLog(1) && (Log() << Verbose(1) << "Vector: ");
    812846  Output();
    813   Log() << Verbose(0) << "\t";
     847  DoLog(0) && (Log() << Verbose(0) << "\t");
    814848  for (int i=NDIM;i--;)
    815849    x[i] -= 2.*projection*n->x[i];
    816   Log() << Verbose(0) << "Projected vector: ";
     850  DoLog(0) && (Log() << Verbose(0) << "Projected vector: ");
    817851  Output();
    818   Log() << Verbose(0) << endl;
     852  DoLog(0) && (Log() << Verbose(0) << endl);
    819853};
    820854
     
    835869  x2.SubtractVector(y2);
    836870  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    837     eLog() << Verbose(2) << "Given vectors are linear dependent." << endl;
     871    DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    838872    return false;
    839873  }
     
    869903  Zero();
    870904  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    871     eLog() << Verbose(2) << "Given vectors are linear dependent." << endl;
     905    DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    872906    return false;
    873907  }
     
    920954  double norm;
    921955
    922   Log() << Verbose(4);
     956  DoLog(4) && (Log() << Verbose(4));
    923957  GivenVector->Output();
    924   Log() << Verbose(0) << endl;
     958  DoLog(0) && (Log() << Verbose(0) << endl);
    925959  for (j=NDIM;j--;)
    926960    Components[j] = -1;
     
    929963    if (fabs(GivenVector->x[j]) > MYEPSILON)
    930964      Components[Last++] = j;
    931   Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;
     965  DoLog(4) && (Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl);
    932966
    933967  switch(Last) {
     
    9791013
    9801014  for (j=0;j<num;j++) {
    981     Log() << Verbose(1) << j << "th atom's vector: ";
     1015    DoLog(1) && (Log() << Verbose(1) << j << "th atom's vector: ");
    9821016    (vectors[j])->Output();
    983     Log() << Verbose(0) << endl;
     1017    DoLog(0) && (Log() << Verbose(0) << endl);
    9841018  }
    9851019
     
    11011135    j += i+1;
    11021136    do {
    1103       Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ";
     1137      DoLog(0) && (Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ");
    11041138      cin >> x[i];
    11051139    } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check));
     
    11321166  B2 = cos(beta) * x2->Norm() * c;
    11331167  C = c * c;
    1134   Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl;
     1168  DoLog(2) && (Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl);
    11351169  int flag = 0;
    11361170  if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping
     
    11711205  D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2];
    11721206  D3 = y->x[0]/x1->x[0]*A-B1;
    1173   Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n";
     1207  DoLog(2) && (Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n");
    11741208  if (fabs(D1) < MYEPSILON) {
    1175     Log() << Verbose(2) << "D1 == 0!\n";
     1209    DoLog(2) && (Log() << Verbose(2) << "D1 == 0!\n");
    11761210    if (fabs(D2) > MYEPSILON) {
    1177       Log() << Verbose(3) << "D2 != 0!\n";
     1211      DoLog(3) && (Log() << Verbose(3) << "D2 != 0!\n");
    11781212      x[2] = -D3/D2;
    11791213      E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2;
    11801214      E2 = -x1->x[1]/x1->x[0];
    1181       Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n";
     1215      DoLog(3) && (Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    11821216      F1 = E1*E1 + 1.;
    11831217      F2 = -E1*E2;
    11841218      F3 = E1*E1 + D3*D3/(D2*D2) - C;
    1185       Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";
     1219      DoLog(3) && (Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    11861220      if (fabs(F1) < MYEPSILON) {
    1187         Log() << Verbose(4) << "F1 == 0!\n";
    1188         Log() << Verbose(4) << "Gleichungssystem linear\n";
     1221        DoLog(4) && (Log() << Verbose(4) << "F1 == 0!\n");
     1222        DoLog(4) && (Log() << Verbose(4) << "Gleichungssystem linear\n");
    11891223        x[1] = F3/(2.*F2);
    11901224      } else {
    11911225        p = F2/F1;
    11921226        q = p*p - F3/F1;
    1193         Log() << Verbose(4) << "p " << p << "\tq " << q << endl;
     1227        DoLog(4) && (Log() << Verbose(4) << "p " << p << "\tq " << q << endl);
    11941228        if (q < 0) {
    1195           Log() << Verbose(4) << "q < 0" << endl;
     1229          DoLog(4) && (Log() << Verbose(4) << "q < 0" << endl);
    11961230          return false;
    11971231        }
     
    12001234      x[0] =  A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2];
    12011235    } else {
    1202       Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n";
     1236      DoLog(2) && (Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n");
    12031237      return false;
    12041238    }
     
    12061240    E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1;
    12071241    E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2];
    1208     Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n";
     1242    DoLog(2) && (Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    12091243    F1 = E2*E2 + D2*D2/(D1*D1) + 1.;
    12101244    F2 = -(E1*E2 + D2*D3/(D1*D1));
    12111245    F3 = E1*E1 + D3*D3/(D1*D1) - C;
    1212     Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";
     1246    DoLog(2) && (Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    12131247    if (fabs(F1) < MYEPSILON) {
    1214       Log() << Verbose(3) << "F1 == 0!\n";
    1215       Log() << Verbose(3) << "Gleichungssystem linear\n";
     1248      DoLog(3) && (Log() << Verbose(3) << "F1 == 0!\n");
     1249      DoLog(3) && (Log() << Verbose(3) << "Gleichungssystem linear\n");
    12161250      x[2] = F3/(2.*F2);
    12171251    } else {
    12181252      p = F2/F1;
    12191253      q = p*p - F3/F1;
    1220       Log() << Verbose(3) << "p " << p << "\tq " << q << endl;
     1254      DoLog(3) && (Log() << Verbose(3) << "p " << p << "\tq " << q << endl);
    12211255      if (q < 0) {
    1222         Log() << Verbose(3) << "q < 0" << endl;
     1256        DoLog(3) && (Log() << Verbose(3) << "q < 0" << endl);
    12231257        return false;
    12241258      }
     
    12581292    for (j=2;j>=0;j--) {
    12591293      k = (i & pot(2,j)) << j;
    1260       Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl;
     1294      DoLog(2) && (Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl);
    12611295      sign[j] = (k == 0) ? 1. : -1.;
    12621296    }
    1263     Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n";
     1297    DoLog(2) && (Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n");
    12641298    // apply sign matrix
    12651299    for (j=NDIM;j--;)
     
    12671301    // calculate angle and check
    12681302    ang = x2->Angle (this);
    1269     Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t";
     1303    DoLog(1) && (Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t");
    12701304    if (fabs(ang - cos(beta)) < MYEPSILON) {
    12711305      break;
Note: See TracChangeset for help on using the changeset viewer.