diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 1549f416a6abde0172abd54106b47686ca01798c..eda68f3dd3707d30279b1bc2045bcd6d4b9807e1 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -199,9 +199,11 @@ bool lineSegmentsIntersect(const GeoLib::Polyline* ply, return false; } -bool isPointInTriangle(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, - double eps_pnt_out_of_plane, +bool isPointInTriangle(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c, + double eps_pnt_out_of_plane, double eps_pnt_out_of_tri, GeoLib::TriangleTest algorithm) { @@ -217,9 +219,11 @@ bool isPointInTriangle(GeoLib::Point const& p, return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane, eps_pnt_out_of_tri); } -bool gaussPointInTriangle(GeoLib::Point const& q, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, - double eps_pnt_out_of_plane, +bool gaussPointInTriangle(MathLib::MathPoint const& q, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c, + double eps_pnt_out_of_plane, double eps_pnt_out_of_tri) { MathLib::Vector3 const v(a, b); @@ -243,11 +247,11 @@ bool gaussPointInTriangle(GeoLib::Point const& q, if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper && y[0] + y[1] <= upper) { - GeoLib::Point const q_projected( + MathLib::MathPoint const q_projected(std::array<double,3>{{ a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1], a[2] + y[0] * v[2] + y[1] * w[2] - ); + }}); if (MathLib::sqrDist(q, q_projected) < eps_pnt_out_of_plane) return true; } @@ -255,9 +259,11 @@ bool gaussPointInTriangle(GeoLib::Point const& q, return false; } -bool barycentricPointInTriangle(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, - double eps_pnt_out_of_plane, +bool barycentricPointInTriangle(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c, + double eps_pnt_out_of_plane, double eps_pnt_out_of_tri) { if (std::abs(orientation3d(p, a, b, c)) > eps_pnt_out_of_plane) @@ -280,8 +286,9 @@ bool barycentricPointInTriangle(GeoLib::Point const& p, return true; } -bool isPointInTetrahedron(GeoLib::Point const& p, GeoLib::Point const& a, GeoLib::Point const& b, - GeoLib::Point const& c, GeoLib::Point const& d, double eps) +bool isPointInTetrahedron(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, MathLib::MathPoint const& b, + MathLib::MathPoint const& c, MathLib::MathPoint const& d, double eps) { double const d0 (orientation3d(d,a,b,c)); // if tetrahedron is not coplanar @@ -309,7 +316,8 @@ bool isPointInTetrahedron(GeoLib::Point const& p, GeoLib::Point const& a, GeoLib return false; } -double calcTriangleArea(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c) +double calcTriangleArea(MathLib::MathPoint const& a, + MathLib::MathPoint const& b, MathLib::MathPoint const& c) { MathLib::Vector3 const u(a,c); MathLib::Vector3 const v(a,b); @@ -445,7 +453,7 @@ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts) (*(pnts[k]))[1] = 0.0; // should be -= d but there are numerical errors } -GeoLib::Point* triangleLineIntersection(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, GeoLib::Point const& p, GeoLib::Point const& q) +GeoLib::Point* triangleLineIntersection(MathLib::MathPoint const& a, MathLib::MathPoint const& b, MathLib::MathPoint const& c, MathLib::MathPoint const& p, MathLib::MathPoint const& q) { const MathLib::Vector3 pq(p, q); const MathLib::Vector3 pa(p, a); @@ -472,8 +480,10 @@ double scalarTriple(MathLib::Vector3 const& u, MathLib::Vector3 const& v, MathLi return MathLib::scalarProduct(cross,w); } -double orientation3d(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c) +double orientation3d(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c) { MathLib::Vector3 const ap (a, p); MathLib::Vector3 const bp (b, p); @@ -481,7 +491,8 @@ double orientation3d(GeoLib::Point const& p, return scalarTriple(bp,cp,ap); } -bool dividedByPlane(const GeoLib::Point& a, const GeoLib::Point& b, const GeoLib::Point& c, const GeoLib::Point& d) +bool dividedByPlane(const MathLib::MathPoint& a, const MathLib::MathPoint& b, + const MathLib::MathPoint& c, const MathLib::MathPoint& d) { for (unsigned x=0; x<3; ++x) { @@ -495,7 +506,8 @@ bool dividedByPlane(const GeoLib::Point& a, const GeoLib::Point& b, const GeoLib return false; } -bool isCoplanar(const GeoLib::Point& a, const GeoLib::Point& b, const GeoLib::Point& c, const GeoLib::Point& d) +bool isCoplanar(const MathLib::MathPoint& a, const MathLib::MathPoint& b, + const MathLib::MathPoint& c, const MathLib::MathPoint& d) { const MathLib::Vector3 ab(a,b); const MathLib::Vector3 ac(a,c); diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index b6e8ed7ebd5e8f409a24629cc9da8e488af69e93..7561a45e5afbd65d3ab2a05224d4cf0944a7072d 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -108,7 +108,8 @@ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts); * The formula is \f$A= \frac{1}{2} \cdot |u \times v|\f$, i.e. half of the area of the * parallelogram specified by the vectors\f$u=b-a\f$ and \f$v=c-a\f$. */ -double calcTriangleArea(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c); +double calcTriangleArea(MathLib::MathPoint const& a, MathLib::MathPoint const& b, + MathLib::MathPoint const& c); /** * Calculates the volume of a tetrahedron. @@ -129,8 +130,10 @@ double calcTetrahedronVolume(const double* x1, const double* x2, const double* x * @param algorithm defines the method to use * @return true if the test point p is within the 'epsilon'-neighbourhood of the triangle */ -bool isPointInTriangle(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, +bool isPointInTriangle(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c, double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon(), GeoLib::TriangleTest algorithm = GeoLib::GAUSS); @@ -148,10 +151,11 @@ bool isPointInTriangle(GeoLib::Point const& p, * @param eps_pnt_out_of_tri eps allowing for p to be slightly off outside of abc * @return true if the test point p is within the 'epsilon'-neighbourhood of the triangle */ -bool gaussPointInTriangle(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, - double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), - double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon()); +bool gaussPointInTriangle(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, MathLib::MathPoint const& b, + MathLib::MathPoint const& c, + double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), + double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon()); /** * Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. @@ -166,10 +170,11 @@ bool gaussPointInTriangle(GeoLib::Point const& p, * @param eps_pnt_out_of_tri eps allowing for p to be slightly off outside of abc * @return true if the test point p is within the 'epsilon'-neighbourhood of the triangle */ -bool barycentricPointInTriangle(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, - double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), - double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon()); +bool barycentricPointInTriangle(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, MathLib::MathPoint const& b, + MathLib::MathPoint const& c, + double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), + double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon()); /** * Tests if the given point p is located within a tetrahedron spanned by points a, b, c, d. @@ -183,8 +188,10 @@ bool barycentricPointInTriangle(GeoLib::Point const& p, * @param eps Accounts for numerical inaccuracies by allowing a point to be slightly outside of the element and still be regarded as inside. * @return true if the test point p is not located outside of abcd (i.e. inside or on a plane/edge). */ -bool isPointInTetrahedron(GeoLib::Point const& p, GeoLib::Point const& a, GeoLib::Point const& b, - GeoLib::Point const& c, GeoLib::Point const& d, double eps = std::numeric_limits<double>::epsilon()); +bool isPointInTetrahedron(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, MathLib::MathPoint const& b, + MathLib::MathPoint const& c, MathLib::MathPoint const& d, + double eps = std::numeric_limits<double>::epsilon()); /** * test for intersections of the line segments of the Polyline @@ -225,7 +232,7 @@ bool lineSegmentIntersect (const GeoLib::Point& a, const GeoLib::Point& b, * This method requires ABC to be counterclockwise and PQ to point downward. * @return Intersection point or NULL if there is no intersection. */ -GeoLib::Point* triangleLineIntersection(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, GeoLib::Point const& p, GeoLib::Point const& q); +GeoLib::Point* triangleLineIntersection(MathLib::MathPoint const& a, MathLib::MathPoint const& b, MathLib::MathPoint const& c, MathLib::MathPoint const& p, MathLib::MathPoint const& q); /// Calculates the scalar triple (u x v) . w double scalarTriple(MathLib::Vector3 const& u, MathLib::Vector3 const& v, MathLib::Vector3 const& w); @@ -239,8 +246,10 @@ double scalarTriple(MathLib::Vector3 const& u, MathLib::Vector3 const& v, MathLi * @return If the triangle abc is ordered counterclockwise when viewed from p, the method will return a negative value, * otherwise it will return a positive value. If p is coplanar with abc, the function will return 0. */ -double orientation3d(GeoLib::Point const& p, - GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c); +double orientation3d(MathLib::MathPoint const& p, + MathLib::MathPoint const& a, + MathLib::MathPoint const& b, + MathLib::MathPoint const& c); /** * Checks if a and b can be placed on a plane such that c and d lie on different sides of said plane. @@ -251,13 +260,13 @@ double orientation3d(GeoLib::Point const& p, * @param d second point to test * @return true, if such a plane can be found, false otherwise */ - bool dividedByPlane(const GeoLib::Point& a, const GeoLib::Point& b, - const GeoLib::Point& c, const GeoLib::Point& d); + bool dividedByPlane(const MathLib::MathPoint& a, const MathLib::MathPoint& b, + const MathLib::MathPoint& c, const MathLib::MathPoint& d); /// Checks if the four given points are located on a plane. - bool isCoplanar(const GeoLib::Point& a, const GeoLib::Point& b, - const GeoLib::Point& c, const GeoLib::Point& d); - + bool isCoplanar(const MathLib::MathPoint& a, const MathLib::MathPoint& b, + const MathLib::MathPoint& c, const MathLib::MathPoint & d); + /** * Method first computes the intersection points of line segements of GeoLib::Polyline objects * (@see computeIntersectionPoints()) and pushes each intersection point in the GeoLib::PointVec