Changes in / [7c14ec:34e0592]


Ignore:
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    r7c14ec r34e0592  
    1111
    1212# Checks for programs.
     13AM_PATH_CPPUNIT(1.9.6)
    1314AC_PROG_CXX
    1415AC_PROG_CC
     16AC_PROG_INSTALL
    1517AC_CHECK_PROG([LATEX],[latex],[latex],[:])
    1618AC_CHECK_PROG([BIBTEX],[bibtex],[bibtex],[:])
  • src/Makefile.am

    r7c14ec r34e0592  
    1 SOURCE = atom.cpp bond.cpp boundary.cpp builder.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     1SOURCE = atom.cpp bond.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
     2HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     3
     4noinst_PROGRAMS =  VectorUnitTest
    35
    46bin_PROGRAMS = molecuilder joiner analyzer
    57molecuilderdir = ${bindir}
    68molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    7 molecuilder_SOURCES =  ${SOURCE} ${HEADER}
     9molecuilder_SOURCES =  ${SOURCE} builder.cpp  ${HEADER}
    810joiner_SOURCES = joiner.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    911analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp
    1012
     13TESTS = VectorUnitTest
     14check_PROGRAMS = $(TESTS)
     15VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp
     16VectorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
     17VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    1118
    1219EXTRA_DIST = ${molecuilder_DATA}
  • src/boundary.cpp

    r7c14ec r34e0592  
    308308
    309309      //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    310       if (ProjectedVector.Projection(&AngleReferenceNormalVector) > 0) {
     310      if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
    311311        angle = 2. * M_PI - angle;
    312312      }
     
    620620  }
    621621
     622  //CalculateConcavityPerBoundaryPoint(out, TesselStruct);
     623  StoreTrianglesinFile(out, mol, filename, "-first");
     624
    622625  // First step: RemovePointFromTesselatedSurface
    623   PointRunner = TesselStruct->PointsOnBoundary.begin();
    624   PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed
    625   while (PointRunner != TesselStruct->PointsOnBoundary.end()) {
    626     PointAdvance++;
    627     point = PointRunner->second;
    628     *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
    629     Concavity = true;
    630     for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
     626  do {
     627    Concavity = false;
     628    PointRunner = TesselStruct->PointsOnBoundary.begin();
     629    PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed
     630    while (PointRunner != TesselStruct->PointsOnBoundary.end()) {
     631      PointAdvance++;
     632      point = PointRunner->second;
     633      *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
     634      for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
     635        line = LineRunner->second;
     636        *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
     637      }
     638      if (!line->CheckConvexityCriterion(out)) {
     639        *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl;
     640        // remove the point
     641        Concavity = true;
     642        TesselStruct->RemovePointFromTesselatedSurface(out, point);
     643      }
     644      PointRunner = PointAdvance;
     645    }
     646
     647    //CalculateConcavityPerBoundaryPoint(out, TesselStruct);
     648    //StoreTrianglesinFile(out, mol, filename, "-second");
     649
     650    // second step: PickFarthestofTwoBaselines
     651    LineRunner = TesselStruct->LinesOnBoundary.begin();
     652    LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
     653    while (LineRunner != TesselStruct->LinesOnBoundary.end()) {
     654      LineAdvance++;
    631655      line = LineRunner->second;
    632       *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    633       Concavity = Concavity && (!line->CheckConvexityCriterion(out));
    634     }
    635     if (Concavity) {
    636       *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl;
    637       // remove the point
    638       TesselStruct->RemovePointFromTesselatedSurface(out, point);
    639     }
    640     PointRunner = PointAdvance;
    641   }
    642 
    643 
    644 //  // print all lines
    645 //  LineRunner = TesselStruct->LinesOnBoundary.begin();
    646 //  LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
    647 //  *out << Verbose(1) << "Printing all boundary lines for debugging." << endl;
    648 //  while (LineRunner != TesselStruct->LinesOnBoundary.end()) {
    649 //    LineAdvance++;
    650 //    line = LineRunner->second;
    651 //    *out << Verbose(2) << "INFO: Current line is " << *line << "." << endl;
    652 //    if (LineAdvance != TesselStruct->LinesOnBoundary.end())
    653 //      *out << Verbose(2) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;
    654 //    LineRunner = LineAdvance;
    655 //  }
    656 //
    657 //  // print all triangles
    658 //  TriangleRunner = TesselStruct->TrianglesOnBoundary.begin();
    659 //  TriangleAdvance = TriangleRunner;  // we need an advanced line, as the LineRunner might get removed
    660 //  *out << Verbose(1) << "Printing all boundary triangles for debugging." << endl;
    661 //  while (TriangleRunner != TesselStruct->TrianglesOnBoundary.end()) {
    662 //    TriangleAdvance++;
    663 //    *out << Verbose(2) << "INFO: Current triangle is " << *(TriangleRunner->second) << "." << endl;
    664 //    if (TriangleAdvance != TesselStruct->TrianglesOnBoundary.end())
    665 //      *out << Verbose(2) << "INFO: Next triangle will be " << *(TriangleAdvance->second) << "." << endl;
    666 //    TriangleRunner = TriangleAdvance;
    667 //  }
    668 
    669   // second step: PickFarthestofTwoBaselines
     656      *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl;
     657      // take highest of both lines
     658      if (TesselStruct->IsConvexRectangle(out, line) == NULL) {
     659        TesselStruct->PickFarthestofTwoBaselines(out, line);
     660        Concavity = true;
     661      }
     662      LineRunner = LineAdvance;
     663    }
     664  } while (Concavity);
     665  CalculateConcavityPerBoundaryPoint(out, TesselStruct);
     666  StoreTrianglesinFile(out, mol, filename, "-third");
     667
     668  // third step: IsConvexRectangle
    670669  LineRunner = TesselStruct->LinesOnBoundary.begin();
    671670  LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
     
    673672    LineAdvance++;
    674673    line = LineRunner->second;
    675     *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl;
    676     if (LineAdvance != TesselStruct->LinesOnBoundary.end())
    677     // take highest of both lines
    678     TesselStruct->PickFarthestofTwoBaselines(out, line);
     674    *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl;
     675    //if (LineAdvance != TesselStruct->LinesOnBoundary.end())
     676      //*out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;
     677    if (!line->CheckConvexityCriterion(out)) {
     678      *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;
     679
     680      // take highest of both lines
     681      point = TesselStruct->IsConvexRectangle(out, line);
     682      if (point != NULL)
     683        TesselStruct->RemovePointFromTesselatedSurface(out, point);
     684    }
    679685    LineRunner = LineAdvance;
    680686  }
    681687
     688  CalculateConcavityPerBoundaryPoint(out, TesselStruct);
     689  StoreTrianglesinFile(out, mol, filename, "-fourth");
     690
     691  // end
     692  *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;
     693  return volume;
     694};
     695
     696/** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation.
     697 * Sets BoundaryPointSet::value equal to the number of connected lines that are not convex.
     698 * \param *out output stream for debugging
     699 * \param *TesselStruct pointer to Tesselation structure
     700 */
     701void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct)
     702{
     703  class BoundaryPointSet *point = NULL;
     704  class BoundaryLineSet *line = NULL;
    682705  // calculate remaining concavity
    683   for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
     706  for (PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
    684707    point = PointRunner->second;
    685708    *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
     
    692715    }
    693716  }
    694 
     717};
     718
     719/** Stores triangles to file.
     720 * \param *out output stream for debugging
     721 * \param *mol molecule with atoms and bonds
     722 * \param *filename prefix of filename
     723 * \param *extraSuffix intermediate suffix
     724 */
     725void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix)
     726{
    695727  // 4. Store triangles in tecplot file
    696728  if (filename != NULL) {
    697729    if (DoTecplotOutput) {
    698730      string OutputName(filename);
    699       OutputName.append("_intermed");
     731      OutputName.append(extraSuffix);
    700732      OutputName.append(TecplotSuffix);
    701733      ofstream *tecplot = new ofstream(OutputName.c_str());
     
    706738    if (DoRaster3DOutput) {
    707739      string OutputName(filename);
    708       OutputName.append("_intermed");
     740      OutputName.append(extraSuffix);
    709741      OutputName.append(Raster3DSuffix);
    710742      ofstream *rasterplot = new ofstream(OutputName.c_str());
     
    714746    }
    715747  }
    716 
    717   // third step: IsConvexRectangle
    718   LineRunner = TesselStruct->LinesOnBoundary.begin();
    719   LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
    720   while (LineRunner != TesselStruct->LinesOnBoundary.end()) {
    721     LineAdvance++;
    722     line = LineRunner->second;
    723     *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl;
    724     if (LineAdvance != TesselStruct->LinesOnBoundary.end())
    725       *out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;
    726     if (!line->CheckConvexityCriterion(out)) {
    727       *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;
    728 
    729       // take highest of both lines
    730       point = TesselStruct->IsConvexRectangle(out, line);
    731       if (point != NULL)
    732         TesselStruct->RemovePointFromTesselatedSurface(out, point);
    733     }
    734     LineRunner = LineAdvance;
    735   }
    736 
    737   // calculate remaining concavity
    738   for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
    739     point = PointRunner->second;
    740     *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
    741     point->value = 0;
    742     for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    743       line = LineRunner->second;
    744       *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    745       if (!line->CheckConvexityCriterion(out))
    746         point->value += 1;
    747     }
    748   }
    749 
    750   // 4. Store triangles in tecplot file
    751   if (filename != NULL) {
    752     if (DoTecplotOutput) {
    753       string OutputName(filename);
    754       OutputName.append(TecplotSuffix);
    755       ofstream *tecplot = new ofstream(OutputName.c_str());
    756       WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);
    757       tecplot->close();
    758       delete(tecplot);
    759     }
    760     if (DoRaster3DOutput) {
    761       string OutputName(filename);
    762       OutputName.append(Raster3DSuffix);
    763       ofstream *rasterplot = new ofstream(OutputName.c_str());
    764       WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);
    765       rasterplot->close();
    766       delete(rasterplot);
    767     }
    768   }
    769 
    770   // end
    771   *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;
    772   return volume;
    773748};
    774749
     
    804779      G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle
    805780      x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node);
    806       x.Scale(runner->second->endpoints[1]->node->node->Projection(&x));
     781      x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x));
    807782      h = x.Norm(); // distance of CoG to triangle
    808783      PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
  • src/boundary.hpp

    r7c14ec r34e0592  
    4242void FindNextSuitablePoint(class BoundaryTriangleSet *BaseTriangle, class BoundaryLineSet *BaseLine, atom*& OptCandidate, Vector *OptCandidateCenter, double *ShortestAngle, const double RADIUS, LinkedCell *LC);
    4343Boundaries *GetBoundaryPoints(ofstream *out, molecule *mol);
     44void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct);
     45void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix);
     46
    4447
    4548#endif /*BOUNDARY_HPP_*/
  • src/builder.cpp

    r7c14ec r34e0592  
    188188          // remove the projection onto the rotation plane of the second angle
    189189          n.CopyVector(&y);
    190           n.Scale(first->x.Projection(&y));
     190          n.Scale(first->x.ScalarProduct(&y));
    191191          cout << "N1: ",
    192192          n.Output((ofstream *)&cout);
     
    197197          cout << endl;
    198198          n.CopyVector(&z);
    199           n.Scale(first->x.Projection(&z));
     199          n.Scale(first->x.ScalarProduct(&z));
    200200          cout << "N2: ",
    201201          n.Output((ofstream *)&cout);
  • src/config.hpp

    r7c14ec r34e0592  
    1818#include "molecules.hpp"
    1919#include "periodentafel.hpp"
     20
     21class ConfigFileBuffer {
     22  public:
     23    char **buffer;
     24    int *LineMapping;
     25    int CurrentLine;
     26    int NoLines;
     27
     28    ConfigFileBuffer();
     29    ConfigFileBuffer(char *filename);
     30    ~ConfigFileBuffer();
     31
     32    void InitMapping();
     33    void MapIonTypesInBuffer(int NoAtoms);
     34};
    2035
    2136/** The config file.
  • src/molecules.cpp

    r7c14ec r34e0592  
    77#include "config.hpp"
    88#include "molecules.hpp"
    9 
    10 /************************************* Other Functions *************************************/
    11 
    12 /** Determines sum of squared distances of \a X to all \a **vectors.
    13  * \param *x reference vector
    14  * \param *params
    15  * \return sum of square distances
    16  */
    17 double LSQ (const gsl_vector * x, void * params)
    18 {
    19   double sum = 0.;
    20   struct LSQ_params *par = (struct LSQ_params *)params;
    21   Vector **vectors = par->vectors;
    22   int num = par->num;
    23 
    24   for (int i=num;i--;) {
    25     for(int j=NDIM;j--;)
    26       sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);
    27   }
    28 
    29   return sum;
    30 };
    319
    3210/************************************* Functions for class molecule *********************************/
  • src/molecules.hpp

    r7c14ec r34e0592  
    2828#include "bond.hpp"
    2929#include "element.hpp"
     30#include "leastsquaremin.hpp"
    3031#include "linkedcell.hpp"
    3132#include "parser.hpp"
     
    8384
    8485
    85 // some algebraic matrix stuff
    86 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
    87 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
    88 
    89 
    90 /** Parameter structure for least square minimsation.
    91  */
    92 struct LSQ_params {
    93   Vector **vectors;
    94   int num;
    95 };
    96 
    97 double LSQ(const gsl_vector * x, void * params);
    98 
    99 /** Parameter structure for least square minimsation.
    100  */
    101 struct lsq_params {
    102   gsl_vector *x;
    103   const molecule *mol;
    104   element *type;
    105 };
    10686
    10787#define MaxThermostats 6      //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
     
    323303};
    324304
    325 class ConfigFileBuffer {
    326   public:
    327     char **buffer;
    328     int *LineMapping;
    329     int CurrentLine;
    330     int NoLines;
    331 
    332     ConfigFileBuffer();
    333     ConfigFileBuffer(char *filename);
    334     ~ConfigFileBuffer();
    335 
    336     void InitMapping();
    337     void MapIonTypesInBuffer(int NoAtoms);
    338 };
    339 
    340305
    341306#endif /*MOLECULES_HPP_*/
  • src/tesselation.cpp

    r7c14ec r34e0592  
    1616  LinesCount = 0;
    1717  Nr = -1;
     18  value = 0.;
    1819};
    1920
     
    2627  LinesCount = 0;
    2728  Nr = Walker->nr;
     29  value = 0.;
    2830};
    2931
     
    148150void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    149151{
    150   cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "."
    151       << endl;
     152  cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
    152153  triangles.insert(TrianglePair(triangle->Nr, triangle));
    153154};
     
    177178  if (triangles.size() != 2) {
    178179    *out << Verbose(1) << "ERROR: Baseline " << *this << " is connect to less than two triangles, Tesselation incomplete!" << endl;
    179     return false;
     180    return true;
    180181  }
    181182  // check normal vectors
    182183  // have a normal vector on the base line pointing outwards
    183   *out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
     184  //*out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    184185  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    185186  BaseLineCenter.AddVector(endpoints[1]->node->node);
     
    187188  BaseLine.CopyVector(endpoints[0]->node->node);
    188189  BaseLine.SubtractVector(endpoints[1]->node->node);
    189   *out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
     190  //*out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    190191
    191192  BaseLineNormal.Zero();
     
    195196  class BoundaryPointSet *node = NULL;
    196197  for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    197     *out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
     198    //*out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    198199    NormalCheck.AddVector(&runner->second->NormalVector);
    199200    NormalCheck.Scale(sign);
     
    202203    node = runner->second->GetThirdEndpoint(this);
    203204    if (node != NULL) {
    204       *out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     205      //*out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    205206      helper[i].CopyVector(node->node->node);
    206207      helper[i].SubtractVector(&BaseLineCenter);
    207208      helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    208       *out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     209      //*out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    209210      i++;
    210211    } else {
    211       *out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;
     212      //*out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;
    212213      return true;
    213214    }
    214215  }
    215   *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     216  //*out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    216217  if (NormalCheck.NormSquared() < MYEPSILON) {
    217     *out << Verbose(3) << "Normalvectors of both triangles are the same: convex." << endl;
     218    *out << Verbose(2) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
    218219    return true;
    219220  }
    220221  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    221   if ((angle - M_PI) > -MYEPSILON)
     222  if ((angle - M_PI) > -MYEPSILON) {
     223    *out << Verbose(2) << "ACCEPT: Angle is greater than pi: convex." << endl;
    222224    return true;
    223   else
     225  } else {
     226    *out << Verbose(2) << "REJECT: Angle is less than pi: concave." << endl;
    224227    return false;
     228  }
    225229}
    226230
     
    349353
    350354  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    351   if (NormalVector.Projection(&OtherVector) > 0)
     355  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    352356    NormalVector.Scale(-1.);
    353357};
     
    737741          TrialVector.CopyVector(checker->second->node->node);
    738742          TrialVector.SubtractVector(A->second->node->node);
    739           distance = TrialVector.Projection(&PlaneVector);
     743          distance = TrialVector.ScalarProduct(&PlaneVector);
    740744          if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    741745            continue;
     
    897901        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    898902        //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    899         if (PropagationVector.Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     903        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    900904          PropagationVector.Scale(-1.);
    901905        *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
     
    957961            TempVector.SubtractVector(Center);
    958962            // make it always point outward
    959             if (VirtualNormalVector.Projection(&TempVector) < 0)
     963            if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
    960964              VirtualNormalVector.Scale(-1.);
    961965            // calculate angle
     
    15301534        AddTesselationLine(TPS[0], TPS[1], 0);
    15311535      }
    1532       cout << Verbose(2) << "Projection is " << BTS->NormalVector.Projection(&Oben) << "." << endl;
     1536      cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
    15331537    }
    15341538    if (BTS != NULL) // we have created one starting triangle
     
    17511755  class BoundaryPointSet *Spot = NULL;
    17521756  class BoundaryLineSet *OtherBase;
    1753   Vector *ClosestPoint[2];
     1757  Vector *ClosestPoint;
    17541758
    17551759  int m=0;
     
    17641768
    17651769  // get the closest point on each line to the other line
    1766   ClosestPoint[0] = GetClosestPointBetweenLine(out, Base, OtherBase);
    1767   ClosestPoint[1] = GetClosestPointBetweenLine(out, OtherBase, Base);
     1770  ClosestPoint = GetClosestPointBetweenLine(out, Base, OtherBase);
    17681771
    17691772  // delete the temporary other base line
     
    17711774
    17721775  // get the distance vector from Base line to OtherBase line
    1773   Vector DistanceToIntersection, BaseLine;
     1776  Vector DistanceToIntersection[2], BaseLine;
     1777  double distance[2];
    17741778  BaseLine.CopyVector(Base->endpoints[1]->node->node);
    17751779  BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    1776   DistanceToIntersection.CopyVector(ClosestPoint[0]);
    1777   DistanceToIntersection.SubtractVector(Base->endpoints[0]->node->node);
    1778   Spot = Base->endpoints[1];
    1779   if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) {
    1780     DistanceToIntersection.CopyVector(ClosestPoint[0]);
    1781     DistanceToIntersection.SubtractVector(Base->endpoints[1]->node->node);
    1782     Spot = Base->endpoints[0];
    1783     if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) {
    1784       *out << Verbose(3) << "ERROR: Something's very wrong here, both SKPs return negative?!" << endl;
    1785       return NULL;
    1786     }
    1787   }
    1788   if ((BaseLine.NormSquared() - DistanceToIntersection.NormSquared()) < -MYEPSILON) {  // distance is smaller: concave
    1789     *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave: Base line squared length " << BaseLine.NormSquared() << " against Distance to intersection squared " << DistanceToIntersection.NormSquared() << "." << endl;
     1780  for (int i=0;i<2;i++) {
     1781    DistanceToIntersection[i].CopyVector(ClosestPoint);
     1782    DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
     1783    distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
     1784  }
     1785  delete(ClosestPoint);
     1786  if ((distance[0] * distance[1]) > 0)  { // have same sign?
     1787    *out << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     1788    if (distance[0] < distance[1]) {
     1789      Spot = Base->endpoints[0];
     1790    } else {
     1791      Spot = Base->endpoints[1];
     1792    }
    17901793    return Spot;
    1791   } else {  // base line is longer: convex
    1792     *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave." << endl;
     1794  } else {  // different sign, i.e. we are in between
     1795    *out << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
    17931796    return NULL;
    17941797  }
     
    17961799};
    17971800
     1801void Tesselation::PrintAllBoundaryPoints(ofstream *out)
     1802{
     1803  // print all lines
     1804  *out << Verbose(1) << "Printing all boundary points for debugging:" << endl;
     1805  for (PointMap::iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
     1806    *out << Verbose(2) << *(PointRunner->second) << endl;
     1807};
     1808
     1809void Tesselation::PrintAllBoundaryLines(ofstream *out)
     1810{
     1811  // print all lines
     1812  *out << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
     1813  for (LineMap::iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
     1814    *out << Verbose(2) << *(LineRunner->second) << endl;
     1815};
     1816
     1817void Tesselation::PrintAllBoundaryTriangles(ofstream *out)
     1818{
     1819  // print all triangles
     1820  *out << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
     1821  for (TriangleMap::iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
     1822    *out << Verbose(2) << *(TriangleRunner->second) << endl;
     1823};
    17981824
    17991825/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    18261852  Distance.SubtractVector(ClosestPoint[0]);
    18271853
    1828   // delete the temporary other base line
     1854  // delete the temporary other base line and the closest points
     1855  delete(ClosestPoint[0]);
     1856  delete(ClosestPoint[1]);
    18291857  delete(OtherBase);
    18301858
     
    18431871      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    18441872    }
    1845     BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     1873    BaseLineNormal.Scale(1./2.);
    18461874
    18471875    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     
    18661894  // construct the plane of the two baselines (i.e. take both their directional vectors)
    18671895  Vector Normal;
    1868   Vector OtherBaseline;
    1869   Normal.CopyVector(Base->endpoints[1]->node->node);
    1870   Normal.SubtractVector(Base->endpoints[0]->node->node);
     1896  Vector Baseline, OtherBaseline;
     1897  Baseline.CopyVector(Base->endpoints[1]->node->node);
     1898  Baseline.SubtractVector(Base->endpoints[0]->node->node);
    18711899  OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node);
    18721900  OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node);
     1901  Normal.CopyVector(&Baseline);
    18731902  Normal.VectorProduct(&OtherBaseline);
    18741903  Normal.Normalize();
    1875 
    1876   // project one offset point of OtherBase onto this plane
     1904  *out << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
     1905
     1906  // project one offset point of OtherBase onto this plane (and add plane offset vector)
    18771907  Vector NewOffset;
    18781908  NewOffset.CopyVector(OtherBase->endpoints[0]->node->node);
     1909  NewOffset.SubtractVector(Base->endpoints[0]->node->node);
    18791910  NewOffset.ProjectOntoPlane(&Normal);
     1911  NewOffset.AddVector(Base->endpoints[0]->node->node);
    18801912  Vector NewDirection;
    1881   NewDirection.CopyVector(OtherBase->endpoints[1]->node->node);
    1882   NewDirection.ProjectOntoPlane(&Normal);
     1913  NewDirection.CopyVector(&NewOffset);
     1914  NewDirection.AddVector(&OtherBaseline);
    18831915
    18841916  // calculate the intersection between this projected baseline and Base
    18851917  Vector *Intersection = new Vector;
    18861918  Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal);
     1919  Normal.CopyVector(Intersection);
     1920  Normal.SubtractVector(Base->endpoints[0]->node->node);
     1921  *out << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl;
    18871922
    18881923  return Intersection;
     
    25952630  int i;
    25962631
     2632  if (point == NULL) {
     2633    *out << Verbose(1) << "ERROR: Cannot remove the point " << point << ", it's NULL!" << endl;
     2634    return 0.;
     2635  } else
     2636    *out << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     2637
    25972638  // copy old location for the volume
    25982639  OldPoint.CopyVector(point->node->node);
     
    26092650    count+=LineRunner->second->triangles.size();
    26102651  numbers = new int[count];
     2652  class BoundaryTriangleSet **Candidates = new BoundaryTriangleSet*[count];
    26112653  i=0;
    26122654  for (LineMap::iterator LineRunner = point->lines.begin(); (point != NULL) && (LineRunner != point->lines.end()); LineRunner++) {
     
    26142656    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    26152657      triangle = TriangleRunner->second;
    2616       *out << Verbose(2) << "Erasing triangle " << *triangle << "." << endl;
     2658      Candidates[i] = triangle;
    26172659      numbers[i++] = triangle->Nr;
    2618       RemoveTesselationTriangle(triangle);
    2619       triangle = NULL;
    2620     }
    2621   }
     2660    }
     2661  }
     2662  for (int j=0;j<i;j++) {
     2663    RemoveTesselationTriangle(Candidates[j]);
     2664  }
     2665  delete[](Candidates);
    26222666  *out << Verbose(1) << i << " triangles were removed." << endl;
    26232667
     
    30233067double GetAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector)
    30243068{
    3025   if (reference.IsNull())
     3069  if (reference.IsZero())
    30263070    return M_PI;
    30273071
    30283072  // calculate both angles and correct with in-plane vector
    3029   if (point.IsNull())
     3073  if (point.IsZero())
    30303074    return M_PI;
    30313075  double phi = point.Angle(&reference);
  • src/tesselation.hpp

    r7c14ec r34e0592  
    230230    bool AddBoundaryPoint(TesselPoint *Walker, int n);
    231231
     232    // print for debugging
     233    void PrintAllBoundaryPoints(ofstream *out);
     234    void PrintAllBoundaryLines(ofstream *out);
     235    void PrintAllBoundaryTriangles(ofstream *out);
     236
     237
    232238    PointMap PointsOnBoundary;
    233239    LineMap LinesOnBoundary;
  • src/tesselationhelpers.cpp

    r7c14ec r34e0592  
    359359  HeightA.SubtractVector(&par.x1);
    360360
    361   t1 = HeightA.Projection(&SideA)/SideA.ScalarProduct(&SideA);
     361  t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA);
    362362
    363363  SideB.CopyVector(&par.x4);
     
    366366  HeightB.SubtractVector(&par.x3);
    367367
    368   t2 = HeightB.Projection(&SideB)/SideB.ScalarProduct(&SideB);
     368  t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB);
    369369
    370370  cout << Verbose(2) << "Intersection " << intersection << " is at "
  • src/vector.cpp

    r7c14ec r34e0592  
    66
    77
    8 #include "molecules.hpp"
    9 
     8#include "defs.hpp"
     9#include "helpers.hpp"
     10#include "leastsquaremin.hpp"
     11#include "vector.hpp"
     12#include "verbose.hpp"
    1013
    1114/************************************ Functions for class vector ************************************/
     
    209212 * \param *PlaneNormal Plane's normal vector
    210213 * \param *PlaneOffset Plane's offset vector
    211  * \param *LineVector first vector of line
    212  * \param *LineVector2 second vector of line
     214 * \param *Origin first vector of line
     215 * \param *LineVector second vector of line
    213216 * \return true -  \a this contains intersection point on return, false - line is parallel to plane
    214217 */
     
    221224  Direction.CopyVector(LineVector);
    222225  Direction.SubtractVector(Origin);
     226  //*out << Verbose(4) << "INFO: Direction is " << Direction << "." << endl;
    223227  factor = Direction.ScalarProduct(PlaneNormal);
    224228  if (factor < MYEPSILON) { // Uniqueness: line parallel to plane?
     
    227231  }
    228232  helper.CopyVector(PlaneOffset);
    229   helper.SubtractVector(LineVector);
     233  helper.SubtractVector(Origin);
    230234  factor = helper.ScalarProduct(PlaneNormal)/factor;
    231235  //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal));
    232236  Direction.Scale(factor);
    233   CopyVector(LineVector);
     237  CopyVector(Origin);
     238  //*out << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl;
    234239  AddVector(&Direction);
    235240
     
    238243  helper.SubtractVector(PlaneOffset);
    239244  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    240     *out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
     245    //*out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
    241246    return true;
    242247  } else {
     
    247252
    248253/** Calculates the intersection of the two lines that are both on the same plane.
    249  * Note that we do not check whether they are on the same plane.
     254 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector
     255 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and
     256 * project onto the first line's direction and add its offset.
    250257 * \param *out output stream for debugging
    251258 * \param *Line1a first vector of first line
     
    258265bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal)
    259266{
    260   double factor1, factor2;
    261   Vector helper, Line, LineNormal, *OtherNormal = NULL;
    262   const Vector *Normal;
    263   bool result = false;
    264 
    265   // create Plane normal vector
    266   if (PlaneNormal == NULL) {
    267     OtherNormal = new Vector(0.,0.,0.);
    268     if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2a))
    269       if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2b)) {
    270         *out << Verbose(1) << "ERROR: GetIntersectionOfTwoLinesOnPlane() cannot create a normal of the plane, everything is linear dependent." << endl;
    271         return false;
    272       }
    273     Normal = OtherNormal;
    274   } else
    275     Normal = PlaneNormal;
    276   *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl;
    277 
    278   // create normal vector to one line
    279   Line.CopyVector(Line1b);
    280   Line.SubtractVector(Line1a);
    281   LineNormal.MakeNormalVector(&Line, Normal);
    282   *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl;
    283 
    284   // check if lines are parallel
    285   helper.CopyVector(Line2b);
    286   helper.SubtractVector(Line2a);
    287   if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) {
    288     *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl;
    289     result = false;
    290   } else { 
    291     helper.CopyVector(Line2a);
    292     helper.SubtractVector(Line1a);
    293     factor1 = helper.ScalarProduct(&LineNormal);
    294     helper.CopyVector(Line2b);
    295     helper.SubtractVector(Line1a);
    296     factor2 = helper.ScalarProduct(&LineNormal);
    297     if (fabs(factor2) > MYEPSILON) {
    298       CopyVector(Line2a);
    299       helper.Scale(factor1/factor2);
    300       AddVector(&helper);
     267  bool result = true;
     268  Vector Direction, OtherDirection;
     269  Vector AuxiliaryNormal;
     270  Vector Distance;
     271  const Vector *Normal = NULL;
     272  Vector *ConstructedNormal = NULL;
     273  bool FreeNormal = false;
     274
     275  // construct both direction vectors
     276  Zero();
     277  Direction.CopyVector(Line1b);
     278  Direction.SubtractVector(Line1a);
     279  if (Direction.IsZero())
     280    return false;
     281  OtherDirection.CopyVector(Line2b);
     282  OtherDirection.SubtractVector(Line2a);
     283  if (OtherDirection.IsZero())
     284    return false;
     285
     286  Direction.Normalize();
     287  OtherDirection.Normalize();
     288
     289  //*out << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl;
     290
     291  if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel
     292    if ((Line1a == Line2a) || (Line1a == Line2b))
     293      CopyVector(Line1a);
     294    else if ((Line1b == Line2b) || (Line1b == Line2b))
     295        CopyVector(Line1b);
     296    else
     297      return false;
     298    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
     299    return true;
     300  } else {
     301    // check whether we have a plane normal vector
     302    if (PlaneNormal == NULL) {
     303      ConstructedNormal = new Vector;
     304      ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection);
     305      Normal = ConstructedNormal;
     306      FreeNormal = true;
     307    } else
     308      Normal = PlaneNormal;
     309
     310    AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal);
     311    //*out << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl;
     312
     313    Distance.CopyVector(Line2a);
     314    Distance.SubtractVector(Line1a);
     315    //*out << Verbose(4) << "INFO: Distance is " << Distance << "." << endl;
     316    if (Distance.IsZero()) {
     317      // offsets are equal, match found
     318      CopyVector(Line1a);
    301319      result = true;
    302320    } else {
    303       Zero();
    304       result = false;
     321      CopyVector(Distance.Projection(&AuxiliaryNormal));
     322      //*out << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl;
     323      double factor = Direction.ScalarProduct(&AuxiliaryNormal);
     324      //*out << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl;
     325      Scale(1./(factor*factor));
     326      //*out << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl;
     327      CopyVector(Projection(&Direction));
     328      //*out << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl;
     329      if (this->IsZero())
     330        result = false;
     331      else
     332        result = true;
     333      AddVector(Line1a);
    305334    }
    306   }
    307 
    308   if (OtherNormal != NULL)
    309     delete(OtherNormal);
     335
     336    if (FreeNormal)
     337      delete(ConstructedNormal);
     338  }
     339  if (result)
     340    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
    310341
    311342  return result;
     
    314345/** Calculates the projection of a vector onto another \a *y.
    315346 * \param *y array to second vector
    316  * \return \f$\langle x, y \rangle\f$
    317  */
    318 double Vector::Projection(const Vector *y) const
    319 {
    320   return (ScalarProduct(y));
     347 */
     348void Vector::ProjectIt(const Vector *y)
     349{
     350  Vector helper(*y);
     351  helper.Scale(-(ScalarProduct(y)));
     352  AddVector(&helper);
     353};
     354
     355/** Calculates the projection of a vector onto another \a *y.
     356 * \param *y array to second vector
     357 * \return Vector
     358 */
     359Vector Vector::Projection(const Vector *y) const
     360{
     361  Vector helper(*y);
     362  helper.Scale((ScalarProduct(y)/y->NormSquared()));
     363
     364  return helper;
    321365};
    322366
     
    380424 * @return true - vector is zero, false - vector is not
    381425 */
    382 bool Vector::IsNull() const
    383 {
    384   return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);
     426bool Vector::IsZero() const
     427{
     428  return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     429};
     430
     431/** Checks whether vector has length of 1.
     432 * @return true - vector is normalized, false - vector is not
     433 */
     434bool Vector::IsOne() const
     435{
     436  return (fabs(Norm() - 1.) < MYEPSILON);
     437};
     438
     439/** Checks whether vector is normal to \a *normal.
     440 * @return true - vector is normalized, false - vector is not
     441 */
     442bool Vector::IsNormalTo(const Vector *normal) const
     443{
     444  if (ScalarProduct(normal) < MYEPSILON)
     445    return true;
     446  else
     447    return false;
    385448};
    386449
     
    392455{
    393456  double norm1 = Norm(), norm2 = y->Norm();
    394   double angle = 1;
     457  double angle = -1;
    395458  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
    396459    angle = this->ScalarProduct(y)/norm1/norm2;
     
    413476  // normalise this vector with respect to axis
    414477  a.CopyVector(this);
    415   a.Scale(Projection(axis));
    416   SubtractVector(&a);
     478  a.ProjectOntoPlane(axis);
    417479  // construct normal vector
    418480  y.MakeNormalVector(axis,this);
     
    427489};
    428490
     491/** Compares vector \a to vector \a b component-wise.
     492 * \param a base vector
     493 * \param b vector components to add
     494 * \return a == b
     495 */
     496bool operator==(const Vector& a, const Vector& b)
     497{
     498  bool status = true;
     499  for (int i=0;i<NDIM;i++)
     500    status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON);
     501  return status;
     502};
     503
    429504/** Sums vector \a to this lhs component-wise.
    430505 * \param a base vector
     
    437512  return a;
    438513};
     514
     515/** Subtracts vector \a from this lhs component-wise.
     516 * \param a base vector
     517 * \param b vector components to add
     518 * \return lhs - a
     519 */
     520Vector& operator-=(Vector& a, const Vector& b)
     521{
     522  a.SubtractVector(&b);
     523  return a;
     524};
     525
    439526/** factor each component of \a a times a double \a m.
    440527 * \param a base vector
     
    461548};
    462549
     550/** Subtracts vector \a from \b component-wise.
     551 * \param a first vector
     552 * \param b second vector
     553 * \return a - b
     554 */
     555Vector& operator-(const Vector& a, const Vector& b)
     556{
     557  Vector *x = new Vector;
     558  x->CopyVector(&a);
     559  x->SubtractVector(&b);
     560  return *x;
     561};
     562
    463563/** Factors given vector \a a times \a m.
    464564 * \param a vector
    465565 * \param m factor
    466  * \return a + b
     566 * \return m * a
    467567 */
    468568Vector& operator*(const Vector& a, const double m)
     569{
     570  Vector *x = new Vector;
     571  x->CopyVector(&a);
     572  x->Scale(m);
     573  return *x;
     574};
     575
     576/** Factors given vector \a a times \a m.
     577 * \param m factor
     578 * \param a vector
     579 * \return m * a
     580 */
     581Vector& operator*(const double m, const Vector& a )
    469582{
    470583  Vector *x = new Vector;
     
    660773  x2.SubtractVector(y2);
    661774  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    662     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     775    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    663776    return false;
    664777  }
     
    694807  Zero();
    695808  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    696     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     809    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    697810    return false;
    698811  }
     
    714827/** Calculates orthonormal vector to one given vectors.
    715828 * Just subtracts the projection onto the given vector from this vector.
     829 * The removed part of the vector is Vector::Projection()
    716830 * \param *x1 vector
    717831 * \return true - success, false - vector is zero
     
    720834{
    721835  bool result = false;
    722   double factor = y1->Projection(this)/y1->Norm()/y1->Norm();
     836  double factor = y1->ScalarProduct(this)/y1->NormSquared();
    723837  Vector x1;
    724838  x1.CopyVector(y1);
     
    777891};
    778892
    779 /** Determines paramter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
     893/** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
    780894 * \param *A first plane vector
    781895 * \param *B second plane vector
     
    790904//  cout << "C " << C->Projection(this) << "\t";
    791905//  cout << endl;
    792   return A->Projection(this);
     906  return A->ScalarProduct(this);
    793907};
    794908
     
    9021016  for (int i=NDIM;i--;)
    9031017    this->x[i] = y->x[i];
     1018}
     1019
     1020/** Copy vector \a y componentwise.
     1021 * \param y vector
     1022 */
     1023void Vector::CopyVector(const Vector y)
     1024{
     1025  for (int i=NDIM;i--;)
     1026    this->x[i] = y.x[i];
    9041027}
    9051028
  • src/vector.hpp

    r7c14ec r34e0592  
    55
    66#include "helpers.hpp"
     7
     8#include <gsl/gsl_vector.h>
     9#include <gsl/gsl_multimin.h>
    710
    811class Vector;
     
    2427  double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const;
    2528  double ScalarProduct(const Vector *y) const;
    26   double Projection(const Vector *y) const;
    2729  double Norm() const;
    2830  double NormSquared() const;
    2931  double Angle(const Vector *y) const;
    30   bool IsNull() const;
     32  bool IsZero() const;
     33  bool IsOne() const;
     34  bool IsNormalTo(const Vector *normal) const;
    3135
    3236  void AddVector(const Vector *y);
    3337  void SubtractVector(const Vector *y);
    3438  void CopyVector(const Vector *y);
     39  void CopyVector(const Vector y);
    3540  void RotateVector(const Vector *y, const double alpha);
    3641  void VectorProduct(const Vector *y);
    3742  void ProjectOntoPlane(const Vector *y);
     43  void ProjectIt(const Vector *y);
     44  Vector Projection(const Vector *y) const;
    3845  void Zero();
    3946  void One(double one);
     
    6471
    6572ostream & operator << (ostream& ost, const Vector &m);
    66 //Vector& operator+=(Vector& a, const Vector& b);
    67 //Vector& operator*=(Vector& a, const double m);
    68 //Vector& operator*(const Vector& a, const double m);
    69 //Vector& operator+(const Vector& a, const Vector& b);
     73bool operator==(const Vector& a, const Vector& b);
     74Vector& operator+=(Vector& a, const Vector& b);
     75Vector& operator-=(Vector& a, const Vector& b);
     76Vector& operator*=(Vector& a, const double m);
     77Vector& operator*(const Vector& a, const double m);
     78Vector& operator*(const double m, const Vector& a);
     79Vector& operator+(const Vector& a, const Vector& b);
     80Vector& operator-(const Vector& a, const Vector& b);
     81
     82// some algebraic matrix stuff
     83#define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
     84#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
     85
     86
    7087
    7188#endif /*VECTOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.