diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index df82df6b56748b532a2f0827d80bee18cd2b4dcd..40cffffc1a71f1ad70c1eade4ca13a2421cfe7bd 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -200,14 +200,29 @@ bool lineSegmentsIntersect(const GeoLib::Polyline* ply, bool isPointInTriangle(const GeoLib::Point* p, const GeoLib::Point* a, const GeoLib::Point* b, const GeoLib::Point* c) { - return isPointInTriangle(*p, *a, *b, *c); + return gaussPointInTriangle(*p, *a, *b, *c); } -bool isPointInTriangle(GeoLib::Point const& q, - GeoLib::Point const& a, - GeoLib::Point const& b, - GeoLib::Point const& c, - double eps) +bool isPointInTriangle(GeoLib::Point const& p, + GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, + double eps_pnt_out_of_plane, double eps_pnt_out_of_tri, + GeoLib::TriangleTest algorithm) +{ + switch (algorithm) + { + case GeoLib::BARYCENTRIC: + return barycentricPointInTriangle(p, a, b, c, eps_pnt_out_of_plane, eps_pnt_out_of_tri); + default: + return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane); + } + return false; +} + +bool gaussPointInTriangle(GeoLib::Point const& q, + GeoLib::Point const& a, + GeoLib::Point const& b, + GeoLib::Point const& c, + double eps) { MathLib::Vector3 const v(a, b); MathLib::Vector3 const w(a, c); @@ -242,7 +257,7 @@ bool isPointInTriangle(GeoLib::Point const& q, return false; } -bool isPointInTriangle2(GeoLib::Point const& p, +bool barycentricPointInTriangle(GeoLib::Point const& p, GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri) { diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index e9de8e473585cc63aeba68c47f62962ecc037cfc..2cc1c30ea6c5877322069b7c30fa8ef8b46d8243 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -27,6 +27,11 @@ namespace GeoLib { class Polyline; +enum TriangleTest +{ + GAUSS, BARYCENTRIC +}; + enum Orientation { CW = 1, CCW = 2, COLLINEAR = 3 @@ -115,6 +120,26 @@ double calcTetrahedronVolume(const double* x1, const double* x2, const double* x bool isPointInTriangle (const GeoLib::Point* p, const GeoLib::Point* a, const GeoLib::Point* b, const GeoLib::Point* c); +/** + * Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. + * Using two eps-values it is possible to test an 'epsilon' neighbourhood around the triangle + * as well as an 'epsilon' outside the triangles plane. + * Algorithm based on "Fundamentals of Computer Graphics" by Peter Shirley. + * @param p test point + * @param a edge node of triangle + * @param b edge node of triangle + * @param c edge node of triangle + * @param eps_pnt_out_of_plane eps allowing for p to be slightly off the plane spanned by abc + * @param eps_pnt_out_of_tri eps allowing for p to be slightly off outside of abc + * @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, + 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); + /** * Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. * Using the eps it is possible to test a 'epsilon' neighbourhood around the triangle. @@ -125,7 +150,7 @@ bool isPointInTriangle (const GeoLib::Point* p, * @param eps size of neighbourhood (orthogonal distance to the plane spaned by triangle) * @return true if the test point p is within the 'epsilon'-neighbourhood of the triangle */ -bool isPointInTriangle(GeoLib::Point const& p, +bool gaussPointInTriangle(GeoLib::Point const& p, GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point const& c, double eps = std::numeric_limits<float>::epsilon()); @@ -142,7 +167,7 @@ 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 isPointInTriangle2(GeoLib::Point const& p, +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());