Index: src/tesselation.cpp
===================================================================
--- src/tesselation.cpp	(revision ffe885d4a42092788786723c1711831629789caa)
+++ src/tesselation.cpp	(revision 09898c37093ccfcb202b1fbcb57f502704896dc9)
@@ -326,4 +326,6 @@
  */
 BoundaryTriangleSet::BoundaryTriangleSet() :
+  top(NULL),
+  AngleFromTop(-1.),
   Nr(-1)
 {
@@ -341,4 +343,6 @@
  */
 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
+  top(NULL),
+  AngleFromTop(-1.),
   Nr(number)
 {
@@ -393,4 +397,9 @@
   }
   //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
+};
+
+void BoundaryTriangleSet::SetTopNode(const BoundaryTriangleSet * const topnode)
+{
+  top = topnode;
 };
 
@@ -995,4 +1004,6 @@
 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
   BaseLine(line),
+  ThirdPoint(NULL),
+  T(NULL),
   ShortestAngle(2.*M_PI),
   OtherShortestAngle(2.*M_PI)
@@ -1004,6 +1015,8 @@
 /** Constructor of class CandidateForTesselation.
  */
-CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
+CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     BaseLine(line),
+    ThirdPoint(point),
+    T(NULL),
     ShortestAngle(2.*M_PI),
     OtherShortestAngle(2.*M_PI)
@@ -1017,5 +1030,4 @@
  */
 CandidateForTesselation::~CandidateForTesselation() {
-  BaseLine = NULL;
 };
 
@@ -1028,14 +1040,20 @@
 bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
 {
+  Info FunctionInfo(__func__);
+
   const double radiusSquared = RADIUS;
   list<const Vector *> VectorList;
   VectorList.push_back(&OptCenter);
-  VectorList.push_back(&OtherOptCenter);
-
+  //VectorList.push_back(&OtherOptCenter);  // don't check the other (wrong) center
+
+  if (!pointlist.empty())
+    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list " << *(*pointlist.begin()) << " and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
+  else
+    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
   // check baseline for OptCenter and OtherOptCenter being on sphere's surface
   for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     for (int i=0;i<2;i++)
       if (fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared) < MYEPSILON) {
-        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << BaseLine->endpoints[i] << " is out of sphere at " << (*VRunner) << "." << endl);
+        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << "." << endl);
         return false;
       }
@@ -1047,5 +1065,5 @@
     for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
       if (fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared) < MYEPSILON) {
-        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << Walker << " is out of sphere at " << (*VRunner) << "." << endl);
+        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << Walker << " is out of sphere at " << *(*VRunner) << "." << endl);
         return false;
       }
@@ -1053,22 +1071,34 @@
   }
 
-  // check for no other points being inside the sphere
+  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
   bool flag = true;
   for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     // get all points inside the sphere
     TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
-    cout << Verbose(1) << "CheckValidity: There are " << ListofPoints->size() << " points inside the sphere at " << (*VRunner) << "." << endl;
     // remove baseline's endpoints and candidates
     for (int i=0;i<2;i++)
       ListofPoints->remove(BaseLine->endpoints[i]->node);
-    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.begin(); ++Runner)
+    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner)
       ListofPoints->remove(*Runner);
     if (!ListofPoints->empty()) {
+      cout << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl;
       flag = false;
-      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << (*VRunner) << ":" << endl);
-      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->begin(); ++Runner)
-        DoeLog(1) && (eLog() << Verbose(1) << "  " << *Runner << endl);
+      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
+      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
+        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
     }
     delete(ListofPoints);
+
+    // check with animate_sphere.tcl VMD script
+    if (ThirdPoint != NULL) {
+      cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " " << ThirdPoint->Nr+1 << " " << RADIUS << " ";
+      cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " ";
+      cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
+    } else {
+      cout << Verbose(1) << "Check by: ... missing third point ..." << endl;
+      cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " ??? " << RADIUS << " ";
+      cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " ";
+      cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
+    }
   }
   return flag;
@@ -2362,14 +2392,16 @@
   Vector SearchDirection;
   Vector helper;
-  TesselPoint *ThirdNode = NULL;
+  BoundaryPointSet *ThirdPoint = NULL;
   LineMap::iterator testline;
   double radius, CircleRadius;
 
   for (int i=0;i<3;i++)
-    if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
-      ThirdNode = T.endpoints[i]->node;
+    if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
+      ThirdPoint = T.endpoints[i];
       break;
     }
-  Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
+  Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl;
+
+  CandidateLine.T = &T;
 
   // construct center of circle
@@ -2398,5 +2430,5 @@
     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
     helper.CopyVector(&CircleCenter);
-    helper.SubtractVector(ThirdNode->node);
+    helper.SubtractVector(ThirdPoint->node->node);
     if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
       SearchDirection.Scale(-1.);
@@ -2408,5 +2440,5 @@
 
     // add third point
-    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
+    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
 
   } else {
@@ -2519,4 +2551,6 @@
   Vector Center;
   TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
+  TesselPointList::iterator Runner;
+  TesselPointList::iterator Sprinter;
 
   // fill the set of neighbours
@@ -2527,10 +2561,11 @@
   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
 
-  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
   Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl;
   for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     Log() << Verbose(0) << " " << **TesselRunner << endl;
-  TesselPointList::iterator Runner = connectedClosestPoints->begin();
-  TesselPointList::iterator Sprinter = Runner;
+
+  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
+  Runner = connectedClosestPoints->begin();
+  Sprinter = Runner;
   Sprinter++;
   while(Sprinter != connectedClosestPoints->end()) {
@@ -2549,9 +2584,17 @@
     AddTesselationTriangle();
     BTS->GetCenter(&Center);
+    BTS->SetTopNode(CandidateLine.T);
+    if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
+      BTS->AngleFromTop = CandidateLine.ShortestAngle;
+    else
+      BTS->AngleFromTop = -1.;
     Center.SubtractVector(&CandidateLine.OptCenter);
     BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     BTS->GetNormalVector(Center);
 
-    Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl;
+    if (CandidateLine.T != NULL)
+      Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl;
+    else
+      Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
     Runner = Sprinter;
     Sprinter++;
@@ -2946,9 +2989,9 @@
  * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
  * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
- * @param ThirdNode third point to avoid in search
+ * @param ThirdPoint third point to avoid in search
  * @param RADIUS radius of sphere
  * @param *LC LinkedCell structure with neighbouring points
  */
-void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const
+void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet  * const ThirdPoint, const double RADIUS, const LinkedCell *LC) const
 {
 	Info FunctionInfo(__func__);
@@ -2971,4 +3014,9 @@
   Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
 
+  // copy old center
+  CandidateLine.OldCenter.CopyVector(&OldSphereCenter);
+  CandidateLine.ThirdPoint = ThirdPoint;
+  CandidateLine.pointlist.clear();
+
   // construct center of circle
   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
@@ -2983,5 +3031,5 @@
   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
 
-  // calculate squared radius TesselPoint *ThirdNode,f circle
+  // calculate squared radius TesselPoint *ThirdPoint,f circle
   radius = CirclePlaneNormal.NormSquared()/4.;
   if (radius < RADIUS*RADIUS) {
@@ -3095,5 +3143,5 @@
                       } else {
                         if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
-                          Log() << Verbose(1) << "REJECT: Old candidate " << *(CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
+                          Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
                         } else {
                           Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
@@ -3107,6 +3155,6 @@
                   }
                 } else {
-                  if (ThirdNode != NULL) {
-                    Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
+                  if (ThirdPoint != NULL) {
+                    Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl;
                   } else {
                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
@@ -3120,11 +3168,10 @@
     }
   } else {
-    if (ThirdNode != NULL)
-      Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
+    if (ThirdPoint != NULL)
+      Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl;
     else
       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;
   }
 
-  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline only ..." << endl);
   if (!CandidateLine.CheckValidity(RADIUS, LC)) {
     DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
Index: src/tesselation.hpp
===================================================================
--- src/tesselation.hpp	(revision ffe885d4a42092788786723c1711831629789caa)
+++ src/tesselation.hpp	(revision 09898c37093ccfcb202b1fbcb57f502704896dc9)
@@ -42,5 +42,5 @@
 
 #define DoTecplotOutput 1
-#define DoRaster3DOutput 0
+#define DoRaster3DOutput 1
 #define DoVRMLOutput 0
 #define TecplotSuffix ".dat"
@@ -163,7 +163,10 @@
     bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
     bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
+    void SetTopNode(const BoundaryTriangleSet * const topnode);
 
     class BoundaryPointSet *endpoints[3];
     class BoundaryLineSet *lines[3];
+    const BoundaryTriangleSet *top; //!< triangle was instantiated during tesselation from this triangle
+    double AngleFromTop;
     Vector NormalVector;
     Vector SphereCenter;
@@ -249,5 +252,5 @@
   public :
   CandidateForTesselation(BoundaryLineSet* currentBaseLine);
-  CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
+  CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, BoundaryPointSet *point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
   ~CandidateForTesselation();
 
@@ -255,5 +258,8 @@
 
   TesselPointList pointlist;
-  BoundaryLineSet *BaseLine;
+  const BoundaryLineSet * BaseLine;
+  const BoundaryPointSet * ThirdPoint;
+  const BoundaryTriangleSet *T;
+  Vector OldCenter;
   Vector OptCenter;
   Vector OtherOptCenter;
@@ -289,5 +295,5 @@
     void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
     void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
-    void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
+    void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
     bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
     int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
