From 4aaa67a01032e12f8bdc20595ae1cf7cecf61002 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Tue, 7 Jun 2016 10:16:24 +0200 Subject: [PATCH] [MaL/GL] Mv orientation3d from GL to MaL. --- GeoLib/AnalyticalGeometry.cpp | 24 +++++++----------------- GeoLib/AnalyticalGeometry.h | 14 -------------- MathLib/GeometricBasics.cpp | 11 +++++++++++ MathLib/GeometricBasics.h | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 0e8375c15cd..9b02181d393 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -24,6 +24,7 @@ #include "PointVec.h" #include "MathLib/LinAlg/Solvers/GaussAlgorithm.h" +#include "MathLib/GeometricBasics.h" extern double orient2d(double *, double *, double *); @@ -300,7 +301,7 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, 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) + if (std::abs(MathLib::orientation3d(p, a, b, c)) > eps_pnt_out_of_plane) return false; MathLib::Vector3 const pa (p,a); @@ -324,25 +325,25 @@ bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a, MathLib::Point3d const& b, MathLib::Point3d const& c, MathLib::Point3d const& d, double eps) { - double const d0 (orientation3d(d,a,b,c)); + double const d0 (MathLib::orientation3d(d,a,b,c)); // if tetrahedron is not coplanar if (std::abs(d0) > std::numeric_limits<double>::epsilon()) { bool const d0_sign (d0>0); // if p is on the same side of bcd as a - double const d1 (orientation3d(d, p, b, c)); + double const d1 (MathLib::orientation3d(d, p, b, c)); if (!(d0_sign == (d1>=0) || std::abs(d1) < eps)) return false; // if p is on the same side of acd as b - double const d2 (orientation3d(d, a, p, c)); + double const d2 (MathLib::orientation3d(d, a, p, c)); if (!(d0_sign == (d2>=0) || std::abs(d2) < eps)) return false; // if p is on the same side of abd as c - double const d3 (orientation3d(d, a, b, p)); + double const d3 (MathLib::orientation3d(d, a, b, p)); if (!(d0_sign == (d3>=0) || std::abs(d3) < eps)) return false; // if p is on the same side of abc as d - double const d4 (orientation3d(p, a, b, c)); + double const d4 (MathLib::orientation3d(p, a, b, c)); if (!(d0_sign == (d4>=0) || std::abs(d4) < eps)) return false; return true; @@ -439,17 +440,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( u * a[2] + v * b[2] + w * c[2])}; } -double orientation3d(MathLib::Point3d const& p, - MathLib::Point3d const& a, - MathLib::Point3d const& b, - MathLib::Point3d const& c) -{ - MathLib::Vector3 const ap (a, p); - MathLib::Vector3 const bp (b, p); - MathLib::Vector3 const cp (c, p); - return MathLib::scalarTriple(bp,cp,ap); -} - bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b, const MathLib::Point3d& c, const MathLib::Point3d& d) { diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index b7a495ff3c1..709cdadfd6c 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -316,20 +316,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( MathLib::Point3d const& c, MathLib::Point3d const& p, MathLib::Point3d const& q); -/** - * Checks if a point p is on the left or right side of a plane spanned by three points a, b, c. - * @param p point to test - * @param a first point on plane - * @param b second point on plane - * @param c third point on plane - * @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(MathLib::Point3d const& p, - MathLib::Point3d const& a, - MathLib::Point3d const& b, - MathLib::Point3d 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. * (In 2D space this checks if c and d are on different sides of a line through a and b.) diff --git a/MathLib/GeometricBasics.cpp b/MathLib/GeometricBasics.cpp index c3fcff04588..5e43c3cc61f 100644 --- a/MathLib/GeometricBasics.cpp +++ b/MathLib/GeometricBasics.cpp @@ -14,6 +14,17 @@ namespace MathLib { +double orientation3d(MathLib::Point3d const& p, + MathLib::Point3d const& a, + MathLib::Point3d const& b, + MathLib::Point3d const& c) +{ + MathLib::Vector3 const ap (a, p); + MathLib::Vector3 const bp (b, p); + MathLib::Vector3 const cp (c, p); + return MathLib::scalarTriple(bp,cp,ap); +} + double calcTetrahedronVolume(MathLib::Point3d const& a, MathLib::Point3d const& b, MathLib::Point3d const& c, diff --git a/MathLib/GeometricBasics.h b/MathLib/GeometricBasics.h index c33fd7b6f59..d5164d5365c 100644 --- a/MathLib/GeometricBasics.h +++ b/MathLib/GeometricBasics.h @@ -19,6 +19,23 @@ namespace MathLib template <typename T, std::size_t DIM> class TemplatePoint; typedef MathLib::TemplatePoint<double,3> Point3d; +/** + * Checks if a point p is on the left or right side of a plane spanned by three + * points a, b, c. + * @param p point to test + * @param a first point on plane + * @param b second point on plane + * @param c third point on plane + * @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(MathLib::Point3d const& p, + MathLib::Point3d const& a, + MathLib::Point3d const& b, + MathLib::Point3d const& c); + /** * Calculates the volume of a tetrahedron. * The formula is V=1/6*|a(b x c)| with a=x1->x2, b=x1->x3 and c=x1->x4. -- GitLab