-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
namespace INTERP_KERNEL
{
- double SquareDistanceFromPtToSegInSpaceDim2(const double *pt, const double *pt0Seg2, const double *pt1Seg2, std::size_t &nbOfHint) throw(INTERP_KERNEL::Exception)
+ /* Orthogonal distance from a point to a plane defined by three points p1, p2, p3.
+ * Returns a signed distance, the normal of the plane being defined by (p1-p2)x(p3-p2)
+ */
+ double OrthoDistanceFromPtToPlaneInSpaceDim3(const double *p, const double *p1, const double *p2, const double *p3)
+ {
+ double prec = 1.0e-14;
+ double T[2][3] = {{p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2]},
+ {p3[0] - p2[0], p3[1] - p2[1], p3[2] - p2[2]}};
+ double N[3] = {T[0][1]*T[1][2]-T[0][2]*T[1][1],
+ T[0][2]*T[1][0]-T[0][0]*T[1][2],
+ T[0][0]*T[1][1]-T[0][1]*T[1][0]};
+
+ double norm2 = N[0]*N[0] + N[1]*N[1] + N[2]*N[2];
+ if (norm2 < prec)
+ throw INTERP_KERNEL::Exception("OrthoDistanceFromPtToPlaneInSpaceDim3: degenerated normal vector!");
+ double num = N[0]*(p[0]-p1[0]) + N[1]*(p[1]-p1[1]) + N[2]*(p[2]-p1[2]);
+ return num/sqrt(norm2);
+ }
+
+ double SquareDistanceFromPtToSegInSpaceDim2(const double *pt, const double *pt0Seg2, const double *pt1Seg2, std::size_t &nbOfHint)
{
double dx=pt1Seg2[0]-pt0Seg2[0],dy=pt1Seg2[1]-pt0Seg2[1];
double norm=sqrt(dx*dx+dy*dy);
return (x-pt[0])*(x-pt[0])+(y-pt[1])*(y-pt[1]);
}
- double DistanceFromPtToTriInSpaceDim3(const double *pt, const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3) throw(INTERP_KERNEL::Exception)
+ double DistanceFromPtToTriInSpaceDim3(const double *pt, const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3)
{
double matrix[12];
if(!ComputeRotTranslationMatrixToPut3PointsOnOXY(pt0Tri3,pt1Tri3,pt2Tri3,matrix))
return sqrt(ret);
}
- double DistanceFromPtToPolygonInSpaceDim3(const double *pt, const int *connOfPolygonBg, const int *connOfPolygonEnd, const double *coords) throw(INTERP_KERNEL::Exception)
+ double DistanceFromPtToPolygonInSpaceDim3(const double *pt, const int *connOfPolygonBg, const int *connOfPolygonEnd, const double *coords)
{
std::size_t nbOfEdges=std::distance(connOfPolygonBg,connOfPolygonEnd);
if(nbOfEdges<3)