Ignore:
Timestamp:
Apr 29, 2010, 1:55:21 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
070651, 5d1a94
Parents:
90c4460 (diff), 32842d8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/tesselation.cpp

    r90c4460 r0d111b  
    1717#include "triangleintersectionlist.hpp"
    1818#include "vector.hpp"
     19#include "vector_ops.hpp"
    1920#include "verbose.hpp"
     21#include "Plane.hpp"
     22#include "Exceptions/LinearDependenceException.hpp"
    2023
    2124class molecule;
     
    234237  // have a normal vector on the base line pointing outwards
    235238  //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    236   BaseLineCenter.CopyVector(endpoints[0]->node->node);
    237   BaseLineCenter.AddVector(endpoints[1]->node->node);
    238   BaseLineCenter.Scale(1. / 2.);
    239   BaseLine.CopyVector(endpoints[0]->node->node);
    240   BaseLine.SubtractVector(endpoints[1]->node->node);
     239  BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
     240  BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
     241
    241242  //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    242243
     
    248249  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    249250    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    250     NormalCheck.AddVector(&runner->second->NormalVector);
    251     NormalCheck.Scale(sign);
     251    NormalCheck += runner->second->NormalVector;
     252    NormalCheck *= sign;
    252253    sign = -sign;
    253254    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    254       BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
     255      BaseLineNormal = runner->second->NormalVector;  // yes, copy second on top of first
    255256    else {
    256257      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
     
    259260    if (node != NULL) {
    260261      //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    261       helper[i].CopyVector(node->node->node);
    262       helper[i].SubtractVector(&BaseLineCenter);
    263       helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
     262      helper[i] = (*node->node->node) - BaseLineCenter;
     263      helper[i].MakeNormalTo(BaseLine);  // we want to compare the triangle's heights' angles!
    264264      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    265265      i++;
     
    409409  Info FunctionInfo(__func__);
    410410  // get normal vector
    411   NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     411  NormalVector = Plane(*(endpoints[0]->node->node),
     412                       *(endpoints[1]->node->node),
     413                       *(endpoints[2]->node->node)).getNormal();
    412414
    413415  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    414   if (NormalVector.ScalarProduct(&OtherVector) > 0.)
     416  if (NormalVector.ScalarProduct(OtherVector) > 0.)
    415417    NormalVector.Scale(-1.);
    416418  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
     
    430432 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    431433 */
     434
    432435bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
    433436{
     
    436439  Vector helper;
    437440
    438   if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
     441  try {
     442    *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x);
     443  }
     444  catch (LinearDependenceException &excp) {
     445    Log() << Verbose(1) << excp;
    439446    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    440447    return false;
     
    445452  DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
    446453
    447   if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
     454  if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
    448455    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
    449456    return true;
    450   } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     457  }   else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
    451458    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
    452459    return true;
    453   } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     460  }   else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
    454461    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
    455462    return true;
     
    458465  int i = 0;
    459466  do {
    460     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) {
    461       helper.CopyVector(endpoints[(i + 1) % 3]->node->node);
    462       helper.SubtractVector(endpoints[i % 3]->node->node);
    463       CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
    464       const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared();
     467    try {
     468      CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node),
     469                                                    *(endpoints[(i+1)%3]->node->node),
     470                                                    *(endpoints[(i+2)%3]->node->node),
     471                                                    *Intersection);
     472      helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
     473      CrossPoint -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     474      const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
    465475      DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
    466       if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) {
     476      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    467477        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
    468         i = 4;
     478        i=4;
    469479        break;
    470480      }
    471481      i++;
    472     } else
     482    } catch (LinearDependenceException &excp){
    473483      break;
     484    }
    474485  } while (i < 3);
    475486  if (i == 3) {
     
    503514  DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
    504515  GetCenter(&Direction);
    505   if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
    506     ClosestPoint->CopyVector(x);
     516  try {
     517    *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction);
     518  }
     519  catch (LinearDependenceException &excp) {
     520    (*ClosestPoint) = (*x);
    507521  }
    508522
    509523  // 2. Calculate in plane part of line (x, intersection)
    510   Vector InPlane;
    511   InPlane.CopyVector(x);
    512   InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
    513   InPlane.ProjectOntoPlane(&NormalVector);
    514   InPlane.AddVector(ClosestPoint);
     524  Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
     525  InPlane.ProjectOntoPlane(NormalVector);
     526  InPlane += *ClosestPoint;
    515527
    516528  DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
     
    526538  for (int i = 0; i < 3; i++) {
    527539    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
    528     Direction.CopyVector(endpoints[(i + 1) % 3]->node->node);
    529     Direction.SubtractVector(endpoints[i % 3]->node->node);
     540    Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    530541    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    531     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node);
    532     CrossDirection[i].CopyVector(&CrossPoint[i]);
    533     CrossDirection[i].SubtractVector(&InPlane);
    534     CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
    535     const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared();
     542    CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     543    CrossDirection[i] = CrossPoint[i] - InPlane;
     544    CrossPoint[i] -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     545    const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
    536546    DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
    537     if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) {
    538       CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again
     547    if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
     548          CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again
    539549      DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
    540       const double distance = CrossPoint[i].DistanceSquared(x);
     550      const double distance = CrossPoint[i].DistanceSquared(*x);
    541551      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    542552        ShortestDistance = distance;
    543         ClosestPoint->CopyVector(&CrossPoint[i]);
     553        (*ClosestPoint) = CrossPoint[i];
    544554      }
    545555    } else
     
    548558  InsideFlag = true;
    549559  for (int i = 0; i < 3; i++) {
    550     const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]);
    551     const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]);
    552     ;
     560    const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
     561    const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
     562
    553563    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
    554564      InsideFlag = false;
    555565  }
    556566  if (InsideFlag) {
    557     ClosestPoint->CopyVector(&InPlane);
    558     ShortestDistance = InPlane.DistanceSquared(x);
     567    (*ClosestPoint) = InPlane;
     568    ShortestDistance = InPlane.DistanceSquared(*x);
    559569  } else { // also check endnodes
    560570    for (int i = 0; i < 3; i++) {
    561       const double distance = x->DistanceSquared(endpoints[i]->node->node);
     571      const double distance = x->DistanceSquared(*endpoints[i]->node->node);
    562572      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    563573        ShortestDistance = distance;
    564         ClosestPoint->CopyVector(endpoints[i]->node->node);
     574        (*ClosestPoint) = (*endpoints[i]->node->node);
    565575      }
    566576    }
     
    667677  center->Zero();
    668678  for (int i = 0; i < 3; i++)
    669     center->AddVector(endpoints[i]->node->node);
     679    (*center) += (*endpoints[i]->node->node);
    670680  center->Scale(1. / 3.);
    671681  DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
     
    733743  int counter = 0;
    734744  for (; Runner[2] != endpoints.end();) {
    735     TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
     745    TemporaryNormal = Plane(*((*Runner[0])->node->node),
     746                            *((*Runner[1])->node->node),
     747                            *((*Runner[2])->node->node)).getNormal();
    736748    for (int i = 0; i < 3; i++) // increase each of them
    737749      Runner[i]++;
    738     TotalNormal->AddVector(&TemporaryNormal);
     750    (*TotalNormal) += TemporaryNormal;
    739751  }
    740752  TotalNormal->Scale(1. / (double) counter);
    741753
    742754  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    743   if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
     755  if (TotalNormal->ScalarProduct(OtherVector) > 0.)
    744756    TotalNormal->Scale(-1.);
    745757  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
     
    758770  center->Zero();
    759771  int counter = 0;
    760   for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    761     center->AddVector((*Runner)->node->node);
     772  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     773    (*center) += (*(*Runner)->node->node);
    762774    counter++;
    763775  }
     
    10201032  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
    10211033{
    1022   Info FunctionInfo(__func__);
    1023   OptCenter.CopyVector(&OptCandidateCenter);
    1024   OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    1025 }
    1026 ;
     1034        Info FunctionInfo(__func__);
     1035  OptCenter = OptCandidateCenter;
     1036  OtherOptCenter = OtherOptCandidateCenter;
     1037};
     1038
    10271039
    10281040/** Destructor for class CandidateForTesselation.
     
    10551067  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    10561068    for (int i = 0; i < 2; i++) {
    1057       const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared);
     1069      const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
    10581070      if (distance > HULLEPSILON) {
    10591071        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     
    10671079    const TesselPoint *Walker = *Runner;
    10681080    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    1069       const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared);
     1081      const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
    10701082      if (distance > HULLEPSILON) {
    10711083        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     
    10851097    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
    10861098    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1087       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl);
     1099      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl);
    10881100
    10891101    // remove baseline's endpoints and candidates
     
    11071119    // check with animate_sphere.tcl VMD script
    11081120    if (ThirdPoint != NULL) {
    1109       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1121      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    11101122    } else {
    11111123      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
    1112       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1124      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    11131125    }
    11141126  }
     
    11791191  int num = 0;
    11801192  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    1181     Center->AddVector(GetPoint()->node);
     1193    (*Center) += (*GetPoint()->node);
    11821194    num++;
    11831195  }
     
    12961308      C++;
    12971309      for (; C != PointsOnBoundary.end(); C++) {
    1298         tmp = A->second->node->node->DistanceSquared(B->second->node->node);
     1310        tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
    12991311        distance = tmp * tmp;
    1300         tmp = A->second->node->node->DistanceSquared(C->second->node->node);
     1312        tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
    13011313        distance += tmp * tmp;
    1302         tmp = B->second->node->node->DistanceSquared(C->second->node->node);
     1314        tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
    13031315        distance += tmp * tmp;
    13041316        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     
    13191331    // 2. next, we have to check whether all points reside on only one side of the triangle
    13201332    // 3. construct plane vector
    1321     PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node);
     1333    PlaneVector = Plane(*A->second->node->node,
     1334                        *baseline->second.first->second->node->node,
     1335                        *baseline->second.second->second->node->node).getNormal();
    13221336    DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
    13231337    // 4. loop over all points
     
    13291343        continue;
    13301344      // 4a. project onto plane vector
    1331       TrialVector.CopyVector(checker->second->node->node);
    1332       TrialVector.SubtractVector(A->second->node->node);
    1333       distance = TrialVector.ScalarProduct(&PlaneVector);
     1345      TrialVector = (*checker->second->node->node);
     1346      TrialVector.SubtractVector(*A->second->node->node);
     1347      distance = TrialVector.ScalarProduct(PlaneVector);
    13341348      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    13351349        continue;
     
    13461360      }
    13471361      // 4d. Check whether the point is inside the triangle (check distance to each node
    1348       tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
     1362      tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
    13491363      int innerpoint = 0;
    1350       if ((tmp < A->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1364      if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
    13511365        innerpoint++;
    1352       tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node);
    1353       if ((tmp < baseline->second.first->second->node->node->DistanceSquared(A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1366      tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
     1367      if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
    13541368        innerpoint++;
    1355       tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node);
    1356       if ((tmp < baseline->second.second->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))
     1369      tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
     1370      if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node)))
    13571371        innerpoint++;
    13581372      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     
    14351449        // prepare some auxiliary vectors
    14361450        Vector BaseLineCenter, BaseLine;
    1437         BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node);
    1438         BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node);
    1439         BaseLineCenter.Scale(1. / 2.); // points now to center of base line
    1440         BaseLine.CopyVector(baseline->second->endpoints[0]->node->node);
    1441         BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node);
     1451        BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
     1452                                (*baseline->second->endpoints[1]->node->node));
     1453        BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
    14421454
    14431455        // offset to center of triangle
    14441456        CenterVector.Zero();
    14451457        for (int i = 0; i < 3; i++)
    1446           CenterVector.AddVector(BTS->endpoints[i]->node->node);
     1458          CenterVector += (*BTS->endpoints[i]->node->node);
    14471459        CenterVector.Scale(1. / 3.);
    14481460        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
    14491461
    14501462        // normal vector of triangle
    1451         NormalVector.CopyVector(Center);
    1452         NormalVector.SubtractVector(&CenterVector);
     1463        NormalVector = (*Center) - CenterVector;
    14531464        BTS->GetNormalVector(NormalVector);
    1454         NormalVector.CopyVector(&BTS->NormalVector);
     1465        NormalVector = BTS->NormalVector;
    14551466        DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
    14561467
    14571468        // vector in propagation direction (out of triangle)
    14581469        // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
    1459         PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
    1460         TempVector.CopyVector(&CenterVector);
    1461         TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
     1470        PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
     1471        TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    14621472        //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    1463         if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     1473        if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
    14641474          PropagationVector.Scale(-1.);
    14651475        DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
     
    14721482
    14731483            // first check direction, so that triangles don't intersect
    1474             VirtualNormalVector.CopyVector(target->second->node->node);
    1475             VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target
    1476             VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    1477             TempAngle = VirtualNormalVector.Angle(&PropagationVector);
     1484            VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
     1485            VirtualNormalVector.ProjectOntoPlane(NormalVector);
     1486            TempAngle = VirtualNormalVector.Angle(PropagationVector);
    14781487            DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
    14791488            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
     
    15021511
    15031512            // check for linear dependence
    1504             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1505             TempVector.SubtractVector(target->second->node->node);
    1506             helper.CopyVector(baseline->second->endpoints[1]->node->node);
    1507             helper.SubtractVector(target->second->node->node);
    1508             helper.ProjectOntoPlane(&TempVector);
     1513            TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
     1514            helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
     1515            helper.ProjectOntoPlane(TempVector);
    15091516            if (fabs(helper.NormSquared()) < MYEPSILON) {
    15101517              DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
     
    15141521            // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
    15151522            flag = true;
    1516             VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
    1517             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1518             TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    1519             TempVector.AddVector(target->second->node->node);
    1520             TempVector.Scale(1. / 3.);
    1521             TempVector.SubtractVector(Center);
     1523            VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
     1524                                        *(baseline->second->endpoints[1]->node->node),
     1525                                        *(target->second->node->node)).getNormal();
     1526            TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
     1527                                    (*baseline->second->endpoints[1]->node->node) +
     1528                                    (*target->second->node->node));
     1529            TempVector -= (*Center);
    15221530            // make it always point outward
    1523             if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
     1531            if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
    15241532              VirtualNormalVector.Scale(-1.);
    15251533            // calculate angle
    1526             TempAngle = NormalVector.Angle(&VirtualNormalVector);
     1534            TempAngle = NormalVector.Angle(VirtualNormalVector);
    15271535            DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
    15281536            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
     
    15321540            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    15331541              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
    1534               helper.CopyVector(target->second->node->node);
    1535               helper.SubtractVector(&BaseLineCenter);
    1536               helper.ProjectOntoPlane(&BaseLine);
     1542              helper = (*target->second->node->node) - BaseLineCenter;
     1543              helper.ProjectOntoPlane(BaseLine);
    15371544              // ...the one with the smaller angle is the better candidate
    1538               TempVector.CopyVector(target->second->node->node);
    1539               TempVector.SubtractVector(&BaseLineCenter);
    1540               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1541               TempAngle = TempVector.Angle(&helper);
    1542               TempVector.CopyVector(winner->second->node->node);
    1543               TempVector.SubtractVector(&BaseLineCenter);
    1544               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1545               if (TempAngle < TempVector.Angle(&helper)) {
    1546                 TempAngle = NormalVector.Angle(&VirtualNormalVector);
     1545              TempVector = (*target->second->node->node) - BaseLineCenter;
     1546              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1547              TempAngle = TempVector.Angle(helper);
     1548              TempVector = (*winner->second->node->node) - BaseLineCenter;
     1549              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1550              if (TempAngle < TempVector.Angle(helper)) {
     1551                TempAngle = NormalVector.Angle(VirtualNormalVector);
    15471552                SmallestAngle = TempAngle;
    15481553                winner = target;
     
    15811586          BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    15821587          BTS->GetCenter(&helper);
    1583           helper.SubtractVector(Center);
    1584           helper.Scale(-1);
     1588          helper -= (*Center);
     1589          helper *= -1;
    15851590          BTS->GetNormalVector(helper);
    15861591          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     
    16401645      DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
    16411646      // we have the intersection, check whether in- or outside of boundary
    1642       if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
     1647      if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
    16431648        // inside, next!
    16441649        DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
     
    16531658          OldPoints[i] = BTS->endpoints[i];
    16541659        }
    1655         Normal.CopyVector(&BTS->NormalVector);
     1660        Normal = BTS->NormalVector;
    16561661        // add Walker to boundary points
    16571662        DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
     
    18001805        // get open line
    18011806        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
    1802           if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(&Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
     1807          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
    18031808            DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
    18041809            insertNewLine = false;
     
    20392044  bool flag = true;
    20402045
    2041   DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);
     2046  DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
    20422047  // get all points inside the sphere
    20432048  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     
    20452050  DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
    20462051  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2047     DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2052    DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl);
    20482053
    20492054  // remove triangles's endpoints
     
    20612066    DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
    20622067    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2063       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2068      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl);
    20642069  }
    20652070  delete (ListofPoints);
     
    22152220        if (List != NULL) {
    22162221          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    2217             if ((*Runner)->node->x[i] > maxCoordinate[i]) {
     2222            if ((*Runner)->node->at(i) > maxCoordinate[i]) {
    22182223              DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
    2219               maxCoordinate[i] = (*Runner)->node->x[i];
     2224              maxCoordinate[i] = (*Runner)->node->at(i);
    22202225              MaxPoint[i] = (*Runner);
    22212226            }
     
    22352240  for (int k = 0; k < NDIM; k++) {
    22362241    NormalVector.Zero();
    2237     NormalVector.x[k] = 1.;
     2242    NormalVector[k] = 1.;
    22382243    BaseLine = new BoundaryLineSet();
    22392244    BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     
    22532258
    22542259    // construct center of circle
    2255     CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
    2256     CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
    2257     CircleCenter.Scale(0.5);
     2260    CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
    22582261
    22592262    // construct normal vector of circle
    2260     CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
    2261     CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
     2263    CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
    22622264
    22632265    double radius = CirclePlaneNormal.NormSquared();
    22642266    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
    22652267
    2266     NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     2268    NormalVector.ProjectOntoPlane(CirclePlaneNormal);
    22672269    NormalVector.Normalize();
    22682270    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
    22692271
    2270     SphereCenter.CopyVector(&NormalVector);
    2271     SphereCenter.Scale(CircleRadius);
    2272     SphereCenter.AddVector(&CircleCenter);
     2272    SphereCenter = (CircleRadius * NormalVector) +  CircleCenter;
    22732273    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    22742274
    22752275    // look in one direction of baseline for initial candidate
    2276     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
     2276    SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ...
    22772277
    22782278    // adding point 1 and point 2 and add the line between them
     
    24782478
    24792479  // construct center of circle
    2480   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2481   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2482   CircleCenter.Scale(0.5);
     2480  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     2481                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    24832482
    24842483  // construct normal vector of circle
    2485   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2486   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2484  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     2485                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
    24872486
    24882487  // calculate squared radius of circle
    2489   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     2488  radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
    24902489  if (radius / 4. < RADIUS * RADIUS) {
    24912490    // construct relative sphere center with now known CircleCenter
    2492     RelativeSphereCenter.CopyVector(&T.SphereCenter);
    2493     RelativeSphereCenter.SubtractVector(&CircleCenter);
     2491    RelativeSphereCenter = T.SphereCenter - CircleCenter;
    24942492
    24952493    CircleRadius = RADIUS * RADIUS - radius / 4.;
     
    25002498
    25012499    // construct SearchDirection and an "outward pointer"
    2502     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
    2503     helper.CopyVector(&CircleCenter);
    2504     helper.SubtractVector(ThirdPoint->node->node);
    2505     if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     2500    SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
     2501    helper = CircleCenter - (*ThirdPoint->node->node);
     2502    if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    25062503      SearchDirection.Scale(-1.);
    25072504    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    2508     if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2505    if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
    25092506      // rotated the wrong way!
    25102507      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
     
    26432640        Finder->second->pointlist.push_back(Sprinter);
    26442641        Finder->second->ShortestAngle = 0.;
    2645         Finder->second->OptCenter.CopyVector(OptCenter);
     2642        Finder->second->OptCenter = *OptCenter;
    26462643      }
    26472644    }
     
    26782675  // create normal vector
    26792676  BTS->GetCenter(&Center);
    2680   Center.SubtractVector(&CandidateLine.OptCenter);
    2681   BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2677  Center -= CandidateLine.OptCenter;
     2678  BTS->SphereCenter = CandidateLine.OptCenter;
    26822679  BTS->GetNormalVector(Center);
    26832680  // give some verbose output about the whole procedure
     
    27122709  AddTesselationTriangle();
    27132710
    2714   BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
     2711  BTS->SphereCenter = CandidateLine.OtherOptCenter;
    27152712  // create normal vector in other direction
    2716   BTS->GetNormalVector(&triangle->NormalVector);
     2713  BTS->GetNormalVector(triangle->NormalVector);
    27172714  BTS->NormalVector.Scale(-1.);
    27182715  // give some verbose output about the whole procedure
     
    27572754  // create normal vector
    27582755  BTS->GetCenter(&Center);
    2759   Center.SubtractVector(OptCenter);
    2760   BTS->SphereCenter.CopyVector(OptCenter);
     2756  Center.SubtractVector(*OptCenter);
     2757  BTS->SphereCenter = *OptCenter;
    27612758  BTS->GetNormalVector(Center);
    27622759
     
    28022799  Vector DistanceToIntersection[2], BaseLine;
    28032800  double distance[2];
    2804   BaseLine.CopyVector(Base->endpoints[1]->node->node);
    2805   BaseLine.SubtractVector(Base->endpoints[0]->node->node);
     2801  BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
    28062802  for (int i = 0; i < 2; i++) {
    2807     DistanceToIntersection[i].CopyVector(ClosestPoint);
    2808     DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    2809     distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
     2803    DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
     2804    distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
    28102805  }
    28112806  delete (ClosestPoint);
     
    28832878
    28842879  // get the distance vector from Base line to OtherBase line
    2885   Vector Distance;
    2886   Distance.CopyVector(ClosestPoint[1]);
    2887   Distance.SubtractVector(ClosestPoint[0]);
     2880  Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
    28882881
    28892882  // calculate volume
     
    29062899    }
    29072900    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2908       DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    2909       BaseLineNormal.AddVector(&(runner->second->NormalVector));
     2901    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
     2902      BaseLineNormal += (runner->second->NormalVector);
    29102903    }
    29112904    BaseLineNormal.Scale(1. / 2.);
    29122905
    2913     if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     2906    if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    29142907      DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
    29152908      // calculate volume summand as a general tetraeder
     
    29472940  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    29482941    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    2949     BaseLineNormal.AddVector(&(runner->second->NormalVector));
     2942    BaseLineNormal += (runner->second->NormalVector);
    29502943  }
    29512944  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     
    30873080              double distance, scaleFactor;
    30883081
    3089               OrthogonalizedOben.CopyVector(&Oben);
    3090               aCandidate.CopyVector(a->node);
    3091               aCandidate.SubtractVector(Candidate->node);
    3092               OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
     3082              OrthogonalizedOben = Oben;
     3083              aCandidate = (*a->node) - (*Candidate->node);
     3084              OrthogonalizedOben.ProjectOntoPlane(aCandidate);
    30933085              OrthogonalizedOben.Normalize();
    30943086              distance = 0.5 * aCandidate.Norm();
     
    30963088              OrthogonalizedOben.Scale(scaleFactor);
    30973089
    3098               Center.CopyVector(Candidate->node);
    3099               Center.AddVector(a->node);
    3100               Center.Scale(0.5);
    3101               Center.AddVector(&OrthogonalizedOben);
    3102 
    3103               AngleCheck.CopyVector(&Center);
    3104               AngleCheck.SubtractVector(a->node);
     3090              Center = 0.5 * ((*Candidate->node) + (*a->node));
     3091              Center += OrthogonalizedOben;
     3092
     3093              AngleCheck = Center - (*a->node);
    31053094              norm = aCandidate.Norm();
    31063095              // second point shall have smallest angle with respect to Oben vector
    31073096              if (norm < RADIUS * 2.) {
    3108                 angle = AngleCheck.Angle(&Oben);
     3097                angle = AngleCheck.Angle(Oben);
    31093098                if (angle < Storage[0]) {
    31103099                  //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     
    31823171
    31833172  // copy old center
    3184   CandidateLine.OldCenter.CopyVector(&OldSphereCenter);
     3173  CandidateLine.OldCenter = OldSphereCenter;
    31853174  CandidateLine.ThirdPoint = ThirdPoint;
    31863175  CandidateLine.pointlist.clear();
    31873176
    31883177  // construct center of circle
    3189   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    3190   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    3191   CircleCenter.Scale(0.5);
     3178  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     3179                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    31923180
    31933181  // construct normal vector of circle
    3194   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    3195   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    3196 
    3197   RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
    3198   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     3182  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     3183                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
     3184
     3185  RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
    31993186
    32003187  // calculate squared radius TesselPoint *ThirdPoint,f circle
     
    32063193
    32073194    // test whether old center is on the band's plane
    3208     if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    3209       DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl);
    3210       RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     3195    if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
     3196      DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl);
     3197      RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
    32113198    }
    32123199    radius = RelativeOldSphereCenter.NormSquared();
     
    32163203      // check SearchDirection
    32173204      DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    3218       if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3205      if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
    32193206        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    32203207      }
     
    32543241                  DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
    32553242
    3256                   if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) {
     3243                  try {
     3244                    NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
     3245                                            *(CandidateLine.BaseLine->endpoints[1]->node->node),
     3246                                            *(Candidate->node)).getNormal();
    32573247                    DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
    3258                     radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     3248                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
    32593249                    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
    32603250                    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    32613251                    DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
    32623252                    if (radius < RADIUS * RADIUS) {
    3263                       otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
     3253                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
    32643254                      if (fabs(radius - otherradius) < HULLEPSILON) {
    32653255                        // construct both new centers
    3266                         NewSphereCenter.CopyVector(&NewPlaneCenter);
    3267                         OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
    3268                         helper.CopyVector(&NewNormalVector);
     3256                        NewSphereCenter = NewPlaneCenter;
     3257                        OtherNewSphereCenter= NewPlaneCenter;
     3258                        helper = NewNormalVector;
    32693259                        helper.Scale(sqrt(RADIUS * RADIUS - radius));
    32703260                        DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
    3271                         NewSphereCenter.AddVector(&helper);
     3261                        NewSphereCenter += helper;
    32723262                        DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
    32733263                        // OtherNewSphereCenter is created by the same vector just in the other direction
    32743264                        helper.Scale(-1.);
    3275                         OtherNewSphereCenter.AddVector(&helper);
     3265                        OtherNewSphereCenter += helper;
    32763266                        DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
    3277 
    32783267                        alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    32793268                        Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    32803269                        if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
    3281                           if (OldSphereCenter.DistanceSquared(&NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))
     3270                          if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
    32823271                            alpha = Otheralpha;
    32833272                        } else
    32843273                          alpha = min(alpha, Otheralpha);
    3285 
    32863274                        // if there is a better candidate, drop the current list and add the new candidate
    32873275                        // otherwise ignore the new candidate and keep the list
    32883276                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
    32893277                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
    3290                             CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    3291                             CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3278                            CandidateLine.OptCenter = NewSphereCenter;
     3279                            CandidateLine.OtherOptCenter = OtherNewSphereCenter;
    32923280                          } else {
    3293                             CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    3294                             CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3281                            CandidateLine.OptCenter = OtherNewSphereCenter;
     3282                            CandidateLine.OtherOptCenter = NewSphereCenter;
    32953283                          }
    32963284                          // if there is an equal candidate, add it to the list without clearing the list
     
    33193307                      DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
    33203308                    }
    3321                   } else {
    3322                     DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl);
     3309                  }
     3310                  catch (LinearDependenceException &excp){
     3311                    Log() << Verbose(1) << excp;
     3312                    Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    33233313                  }
    33243314                } else {
     
    34163406            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    34173407            if (FindPoint != PointsOnBoundary.end()) {
    3418               points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));
     3408              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
    34193409              DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
    34203410            }
     
    34603450    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    34613451      // calculate closest point on line to desired point
    3462       helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3463       helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
    3464       helper.Scale(0.5);
    3465       Center.CopyVector(x);
    3466       Center.SubtractVector(&helper);
    3467       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3468       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3469       Center.ProjectOntoPlane(&BaseLine);
     3452      helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
     3453                      (*(LineRunner->second)->endpoints[1]->node->node));
     3454      Center = (*x) - helper;
     3455      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3456                 (*(LineRunner->second)->endpoints[1]->node->node);
     3457      Center.ProjectOntoPlane(BaseLine);
    34703458      const double distance = Center.NormSquared();
    34713459      if ((ClosestLine == NULL) || (distance < MinDistance)) {
    34723460        // additionally calculate intersection on line (whether it's on the line section or not)
    3473         helper.CopyVector(x);
    3474         helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
    3475         helper.SubtractVector(&Center);
    3476         const double lengthA = helper.ScalarProduct(&BaseLine);
    3477         helper.CopyVector(x);
    3478         helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3479         helper.SubtractVector(&Center);
    3480         const double lengthB = helper.ScalarProduct(&BaseLine);
     3461        helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
     3462        const double lengthA = helper.ScalarProduct(BaseLine);
     3463        helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
     3464        const double lengthB = helper.ScalarProduct(BaseLine);
    34813465        if (lengthB * lengthA < 0) { // if have different sign
    34823466          ClosestLine = LineRunner->second;
     
    35273511    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    35283512
    3529       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3530       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3513      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3514                 (*(LineRunner->second)->endpoints[1]->node->node);
    35313515      const double lengthBase = BaseLine.NormSquared();
    35323516
    3533       BaseLineIntersection.CopyVector(x);
    3534       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3517      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
    35353518      const double lengthEndA = BaseLineIntersection.NormSquared();
    35363519
    3537       BaseLineIntersection.CopyVector(x);
    3538       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3520      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
    35393521      const double lengthEndB = BaseLineIntersection.NormSquared();
    35403522
     
    35543536      } else { // intersection is closer, calculate
    35553537        // calculate closest point on line to desired point
    3556         BaseLineIntersection.CopyVector(x);
    3557         BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3558         Center.CopyVector(&BaseLineIntersection);
    3559         Center.ProjectOntoPlane(&BaseLine);
    3560         BaseLineIntersection.SubtractVector(&Center);
     3538        BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
     3539        Center = BaseLineIntersection;
     3540        Center.ProjectOntoPlane(BaseLine);
     3541        BaseLineIntersection -= Center;
    35613542        const double distance = BaseLineIntersection.NormSquared();
    35623543        if (Center.NormSquared() > BaseLine.NormSquared()) {
     
    36123593  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    36133594    (*Runner)->GetCenter(&Center);
    3614     helper.CopyVector(x);
    3615     helper.SubtractVector(&Center);
    3616     const double Alignment = helper.Angle(&(*Runner)->NormalVector);
     3595    helper = (*x) - Center;
     3596    const double Alignment = helper.Angle((*Runner)->NormalVector);
    36173597    if (Alignment < MinAlignment) {
    36183598      result = *Runner;
     
    36813661  triangle->GetCenter(&Center);
    36823662  DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
    3683   DistanceToCenter.CopyVector(&Center);
    3684   DistanceToCenter.SubtractVector(&Point);
     3663  DistanceToCenter = Center - Point;
    36853664  DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
    36863665
    36873666  // check whether we are on boundary
    3688   if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     3667  if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
    36893668    // calculate whether inside of triangle
    3690     DistanceToCenter.CopyVector(&Point);
    3691     Center.CopyVector(&Point);
    3692     Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
    3693     DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
     3669    DistanceToCenter = Point + triangle->NormalVector; // points outside
     3670    Center = Point - triangle->NormalVector; // points towards MolCenter
    36943671    DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
    36953672    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
     
    37063683
    37073684    // then check direction to boundary
    3708     if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
     3685    if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
    37093686      DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
    37103687      return -distance;
     
    38403817  if ((triangles != NULL) && (!triangles->empty())) {
    38413818    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3842       PlaneNormal.AddVector(&(*Runner)->NormalVector);
     3819      PlaneNormal += (*Runner)->NormalVector;
    38433820  } else {
    38443821    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
     
    38513828  // construct one orthogonal vector
    38523829  if (Reference != NULL) {
    3853     AngleZero.CopyVector(Reference);
    3854     AngleZero.SubtractVector(Point->node);
    3855     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3830    AngleZero = (*Reference) - (*Point->node);
     3831    AngleZero.ProjectOntoPlane(PlaneNormal);
    38563832  }
    38573833  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
    38583834    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    3859     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3860     AngleZero.SubtractVector(Point->node);
    3861     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3835    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3836    AngleZero.ProjectOntoPlane(PlaneNormal);
    38623837    if (AngleZero.NormSquared() < MYEPSILON) {
    38633838      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     
    38673842  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    38683843  if (AngleZero.NormSquared() > MYEPSILON)
    3869     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3844    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    38703845  else
    3871     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3846    OrthogonalVector.MakeNormalTo(PlaneNormal);
    38723847  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    38733848
    38743849  // go through all connected points and calculate angle
    38753850  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3876     helper.CopyVector((*listRunner)->node);
    3877     helper.SubtractVector(Point->node);
    3878     helper.ProjectOntoPlane(&PlaneNormal);
     3851    helper = (*(*listRunner)->node) - (*Point->node);
     3852    helper.ProjectOntoPlane(PlaneNormal);
    38793853    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    38803854    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
     
    39343908  int counter = 0;
    39353909  while (TesselC != SetOfNeighbours->end()) {
    3936     helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
     3910    helper = Plane(*((*TesselA)->node),
     3911                   *((*TesselB)->node),
     3912                   *((*TesselC)->node)).getNormal();
    39373913    DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
    39383914    counter++;
     
    39403916    TesselB++;
    39413917    TesselC++;
    3942     PlaneNormal.AddVector(&helper);
     3918    PlaneNormal += helper;
    39433919  }
    39443920  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
     
    39553931  // construct one orthogonal vector
    39563932  if (Reference != NULL) {
    3957     AngleZero.CopyVector(Reference);
    3958     AngleZero.SubtractVector(Point->node);
    3959     AngleZero.ProjectOntoPlane(&PlaneNormal);
    3960   }
    3961   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3933    AngleZero = (*Reference) - (*Point->node);
     3934    AngleZero.ProjectOntoPlane(PlaneNormal);
     3935  }
     3936  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    39623937    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    3963     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3964     AngleZero.SubtractVector(Point->node);
    3965     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3938    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3939    AngleZero.ProjectOntoPlane(PlaneNormal);
    39663940    if (AngleZero.NormSquared() < MYEPSILON) {
    39673941      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     
    39713945  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    39723946  if (AngleZero.NormSquared() > MYEPSILON)
    3973     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3947    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    39743948  else
    3975     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3949    OrthogonalVector.MakeNormalTo(PlaneNormal);
    39763950  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    39773951
     
    39793953  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
    39803954  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3981     helper.CopyVector((*listRunner)->node);
    3982     helper.SubtractVector(Point->node);
    3983     helper.ProjectOntoPlane(&PlaneNormal);
     3955    helper = (*(*listRunner)->node) - (*Point->node);
     3956    helper.ProjectOntoPlane(PlaneNormal);
    39843957    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    39853958    if (angle > M_PI) // the correction is of no use here (and not desired)
     
    42254198
    42264199  // copy old location for the volume
    4227   OldPoint.CopyVector(point->node->node);
     4200  OldPoint = (*point->node->node);
    42284201
    42294202  // get list of connected points
     
    42534226  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    42544227    DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
    4255     NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     4228    NormalVector -= Runner->second->NormalVector; // has to point inward
    42564229    RemoveTesselationTriangle(Runner->second);
    42574230    count++;
     
    42884261          StartNode--;
    42894262          //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
    4290           Point.CopyVector((*StartNode)->node);
    4291           Point.SubtractVector((*MiddleNode)->node);
     4263          Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
    42924264          StartNode = MiddleNode;
    42934265          StartNode++;
     
    42954267            StartNode = connectedPath->begin();
    42964268          //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
    4297           Reference.CopyVector((*StartNode)->node);
    4298           Reference.SubtractVector((*MiddleNode)->node);
    4299           OrthogonalVector.CopyVector((*MiddleNode)->node);
    4300           OrthogonalVector.SubtractVector(&OldPoint);
    4301           OrthogonalVector.MakeNormalVector(&Reference);
     4269          Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
     4270          OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
     4271          OrthogonalVector.MakeNormalTo(Reference);
    43024272          angle = GetAngle(Point, Reference, OrthogonalVector);
    43034273          //if (angle < M_PI)  // no wrong-sided triangles, please?
     
    47524722  class BoundaryLineSet *BestLine = NULL;
    47534723  for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
    4754     BaseLine.CopyVector(Runner->second->endpoints[0]->node->node);
    4755     BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node);
    4756     CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node);
    4757     CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node);
    4758     CenterToPoint.Scale(0.5);
    4759     CenterToPoint.SubtractVector(point->node);
    4760     angle = CenterToPoint.Angle(&BaseLine);
    4761     if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) {
     4724    BaseLine = (*Runner->second->endpoints[0]->node->node) -
     4725               (*Runner->second->endpoints[1]->node->node);
     4726    CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
     4727                           (*Runner->second->endpoints[1]->node->node));
     4728    CenterToPoint -= (*point->node);
     4729    angle = CenterToPoint.Angle(BaseLine);
     4730    if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
    47624731      BestAngle = angle;
    47634732      BestLine = Runner->second;
     
    49254894      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    49264895        if (VectorWalker != VectorRunner) { // skip equals
    4927           const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4896          const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
    49284897          DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
    49294898          if (fabs(SCP + 1.) < ParallelEpsilon) {
     
    50104979    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
    50114980    /// 4a. Get NormalVector for one side (this is "front")
    5012     NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4981    NormalVector = (*TriangleWalker)->NormalVector;
    50134982    DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
    50144983    TriangleWalker++;
     
    50214990      TriangleSprinter++;
    50224991      DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
    5023       if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
     4992      if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
    50244993        DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
    50254994        TriangleNrs.push(triangle->Nr);
     
    50435012      AddTesselationTriangle(); // ... and add
    50445013      TriangleNrs.pop();
    5045       BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    5046       BTS->NormalVector.Scale(-1.);
     5014      BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
    50475015      TriangleWalker++;
    50485016    }
Note: See TracChangeset for help on using the changeset viewer.