From 4feda7ef5075a329771a2cf3a481403067531ac3 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Tue, 7 Jun 2016 10:53:53 +0200 Subject: [PATCH] [MaL/GL] Mv calcTriangleArea() from GL to MaL. --- GeoLib/AnalyticalGeometry.cpp | 9 --------- GeoLib/AnalyticalGeometry.h | 8 -------- GeoLib/IO/TINInterface.cpp | 4 +++- MathLib/GeometricBasics.cpp | 9 +++++++++ MathLib/GeometricBasics.h | 9 +++++++++ MeshLib/Elements/QuadRule4.cpp | 5 +++-- MeshLib/Elements/TriRule3.cpp | 3 ++- NumLib/Function/LinearInterpolationOnSurface.cpp | 5 +++-- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index b8006bd6c43..51e46fefd17 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -321,15 +321,6 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, return true; } -double calcTriangleArea(MathLib::Point3d const& a, - MathLib::Point3d const& b, MathLib::Point3d const& c) -{ - MathLib::Vector3 const u(a,c); - MathLib::Vector3 const v(a,b); - MathLib::Vector3 const w(MathLib::crossProduct(u, v)); - return 0.5 * w.getLength(); -} - void computeRotationMatrixToXZ(MathLib::Vector3 const& plane_normal, MathLib::DenseMatrix<double> & rot_mat) { // *** some frequently used terms *** diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index cf5f1d83c5a..a02c7cdd8e9 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -176,14 +176,6 @@ MathLib::DenseMatrix<double> rotatePointsToXY(InputIterator1 p_pnts_begin, */ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts); -/** - * Calculates the area of the triangle defined by its edge nodes a, b and c. - * 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(MathLib::Point3d const& a, MathLib::Point3d const& b, - MathLib::Point3d const& 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 diff --git a/GeoLib/IO/TINInterface.cpp b/GeoLib/IO/TINInterface.cpp index 566e2ea6ec2..ab9a892d431 100644 --- a/GeoLib/IO/TINInterface.cpp +++ b/GeoLib/IO/TINInterface.cpp @@ -20,6 +20,8 @@ #include "GeoLib/Surface.h" #include "GeoLib/Triangle.h" +#include "MathLib/GeometricBasics.h" + namespace GeoLib { namespace IO @@ -92,7 +94,7 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, // check area of triangle double const d_eps(std::numeric_limits<double>::epsilon()); - if (GeoLib::calcTriangleArea(p0, p1, p2) < d_eps) { + if (MathLib::calcTriangleArea(p0, p1, p2) < d_eps) { ERR("readTIN: Triangle %d has zero area.", id); if (errors) errors->push_back (std::string("readTIN: Triangle ") diff --git a/MathLib/GeometricBasics.cpp b/MathLib/GeometricBasics.cpp index caab906d2d3..3d26f8e877f 100644 --- a/MathLib/GeometricBasics.cpp +++ b/MathLib/GeometricBasics.cpp @@ -36,6 +36,15 @@ double calcTetrahedronVolume(MathLib::Point3d const& a, return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0; } +double calcTriangleArea(MathLib::Point3d const& a, MathLib::Point3d const& b, + MathLib::Point3d const& c) +{ + MathLib::Vector3 const u(a, c); + MathLib::Vector3 const v(a, b); + MathLib::Vector3 const w(MathLib::crossProduct(u, v)); + return 0.5 * w.getLength(); +} + bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a, MathLib::Point3d const& b, MathLib::Point3d const& c, MathLib::Point3d const& d, double eps) diff --git a/MathLib/GeometricBasics.h b/MathLib/GeometricBasics.h index e97a9b5e407..ba569dddbf3 100644 --- a/MathLib/GeometricBasics.h +++ b/MathLib/GeometricBasics.h @@ -45,6 +45,15 @@ double calcTetrahedronVolume(MathLib::Point3d const& x1, MathLib::Point3d const& x2, MathLib::Point3d const& x3, MathLib::Point3d const& x4); + +/** + * Calculates the area of the triangle defined by its edge nodes a, b and c. + * 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(MathLib::Point3d const& a, MathLib::Point3d const& b, + MathLib::Point3d const& c); + /** * Tests if the given point p is located within a tetrahedron spanned by points * a, b, c, d. diff --git a/MeshLib/Elements/QuadRule4.cpp b/MeshLib/Elements/QuadRule4.cpp index b1ec6e43cb6..fec69003205 100644 --- a/MeshLib/Elements/QuadRule4.cpp +++ b/MeshLib/Elements/QuadRule4.cpp @@ -12,6 +12,7 @@ #include "logog/include/logog.hpp" #include "GeoLib/AnalyticalGeometry.h" +#include "MathLib/GeometricBasics.h" #include "MeshLib/Node.h" @@ -27,8 +28,8 @@ const unsigned QuadRule4::edge_nodes[4][2] = double QuadRule4::computeVolume(Node const* const* _nodes) { - return GeoLib::calcTriangleArea(*_nodes[0], *_nodes[1], *_nodes[2]) - + GeoLib::calcTriangleArea(*_nodes[2], *_nodes[3], *_nodes[0]); + return MathLib::calcTriangleArea(*_nodes[0], *_nodes[1], *_nodes[2]) + + MathLib::calcTriangleArea(*_nodes[2], *_nodes[3], *_nodes[0]); } bool QuadRule4::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps) diff --git a/MeshLib/Elements/TriRule3.cpp b/MeshLib/Elements/TriRule3.cpp index 2da9a0877c0..0927588134c 100644 --- a/MeshLib/Elements/TriRule3.cpp +++ b/MeshLib/Elements/TriRule3.cpp @@ -12,6 +12,7 @@ #include "logog/include/logog.hpp" #include "GeoLib/AnalyticalGeometry.h" +#include "MathLib/GeometricBasics.h" #include "MeshLib/Node.h" @@ -26,7 +27,7 @@ const unsigned TriRule3::edge_nodes[3][2] = double TriRule3::computeVolume(Node const* const* _nodes) { - return GeoLib::calcTriangleArea(*_nodes[0], *_nodes[1], *_nodes[2]); + return MathLib::calcTriangleArea(*_nodes[0], *_nodes[1], *_nodes[2]); } bool TriRule3::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps) diff --git a/NumLib/Function/LinearInterpolationOnSurface.cpp b/NumLib/Function/LinearInterpolationOnSurface.cpp index 27fd3cc3455..a9a0da32ffc 100644 --- a/NumLib/Function/LinearInterpolationOnSurface.cpp +++ b/NumLib/Function/LinearInterpolationOnSurface.cpp @@ -17,10 +17,11 @@ #include <cassert> #include <numeric> -#include "MathLib/Vector3.h" #include "GeoLib/Surface.h" #include "GeoLib/Triangle.h" #include "GeoLib/AnalyticalGeometry.h" +#include "MathLib/Vector3.h" +#include "MathLib/GeometricBasics.h" #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" #include "MeshGeoToolsLib/MeshNodesAlongSurface.h" @@ -77,7 +78,7 @@ double LinearInterpolationOnSurface::interpolateInTri( GeoLib::Point const& v2(pnts[1]); GeoLib::Point const& v3(pnts[2]); GeoLib::Point const& v_pnt(pnts[3]); - const double area = GeoLib::calcTriangleArea(v1, v2, v3); + const double area = MathLib::calcTriangleArea(v1, v2, v3); if (area==.0) { // take average if all points have the same coordinates -- GitLab