+
+ // In open contour case
+ if (lstPointsX.size()==2)
+ {
+ double cx,cy,cz,r1,r2;
+ i = 0;
+ cx = (lstPointsX[i]+lstPointsX[i+1]) / 2;
+ cy = (lstPointsY[i]+lstPointsY[i+1]) / 2;
+ cz = (lstPointsZ[i]+lstPointsZ[i+1]) / 2;
+ r1 = DistanceSQ( cx,cy,cz,x,y,z );
+ r2 = DistanceSQ( cx,cy,cz,lstPointsX[i], lstPointsY[i], lstPointsZ[i] );
+ if (r1<r2) // inside circle
+ {
+ pos=1;
+ } else { // outside circle
+ if (a<b) // befor first point
+ {
+ pos=0;
+ } else { // after second point
+ pos=2;
+ }
+ }
+
+ }
+ if (lstPointsX.size()>2)
+ {
+ double r3;
+ if ( pos==1) // first point of the list
+ {
+ i = 0;
+ a = DistanceSQ(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]);
+ b = DistanceSQ(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]);
+ r3 = DistanceSQ( lstPointsX[i], lstPointsY[i], lstPointsZ[i],lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1] );
+ if (b>r3) // outside circle
+ {
+ pos = 0;
+ }
+ }
+ if (pos==lstPointsX.size()-1 ) // last point of the list
+ {
+ i = lstPointsX.size()-2;
+ r3 = DistanceSQ( lstPointsX[i], lstPointsY[i], lstPointsZ[i],lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1] );
+ if (a>r3) // outside circle
+ {
+ pos = pos+1;
+ }
+ }
+ }
+
+