diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 362b8451d8cd9ea3eee7ea96e578c8ad479c1148..3b9bccae479a0a4b82789f8007aa09bb9bd0fbeb 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -250,6 +250,14 @@ double calcTriangleArea(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib:: return 0.5 * w.getLength(); } +double calcTetrahedronVolume(const double* x1, const double* x2, const double* x3, const double* x4) +{ + const MathLib::Vector3 ab(x1, x2); + const MathLib::Vector3 ac(x1, x3); + const MathLib::Vector3 ad(x1, x4); + return GeoLib::scalarTriple(ab, ac, ad) / 6.0; +} + // NewellPlane from book Real-Time Collision detection p. 494 void getNewellPlane(const std::vector<GeoLib::Point*>& pnts, MathLib::Vector3 &plane_normal, double& d) { @@ -459,4 +467,5 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec, } } + } // end namespace GeoLib diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index 9a705b5d1e2828dd27a2c94107a0a7b99696bc3a..5ca4905023f3c0a25791b7ad28513ffe8d9b7161 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -106,6 +106,12 @@ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts); */ double calcTriangleArea(GeoLib::Point const& a, GeoLib::Point const& b, GeoLib::Point 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. + */ +double calcTetrahedronVolume(const double* x1, const double* x2, const double* x3, const double* x4); + bool isPointInTriangle (const GeoLib::Point* p, const GeoLib::Point* a, const GeoLib::Point* b, const GeoLib::Point* c); @@ -194,6 +200,7 @@ void computeAndInsertAllIntersectionPoints( GeoLib::PointVec &pnt_vec, std::vector<GeoLib::Polyline*> & plys); + } // end namespace GeoLib #endif /* ANALYTICAL_GEOMETRY_H_ */ diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp index a086660e996d0f8a01256e1c90eb0ba8a49489c7..fe2bbc9673ee0255eda98d9b30024b180370f637 100644 --- a/MathLib/MathTools.cpp +++ b/MathLib/MathTools.cpp @@ -62,11 +62,6 @@ double getAngle (const double p0[3], const double p1[3], const double p2[3]) return acos (scalarProduct<double,3> (v0,v1) / (sqrt(scalarProduct<double,3>(v0,v0)) * sqrt(scalarProduct<double,3>(v1,v1)))); } -double calcTetrahedronVolume(const double* x1, const double* x2, const double* x3, const double* x4) -{ - return fabs((x1[0] - x4[0]) * ((x2[1] - x4[1]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[1] - x4[1])) - - (x1[1] - x4[1]) * ((x2[0] - x4[0]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[0] - x4[0])) - + (x1[2] - x4[2]) * ((x2[0] - x4[0]) * (x3[1] - x4[1]) - (x2[1] - x4[1]) * (x3[0] - x4[0]))) / 6.0; -} + } // namespace diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 8c78efca61690d9c1f4cc4dca30118855648d0af..47357fc6368af9b61345ed03bbd8372ae00cf9de 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -148,11 +148,6 @@ float normalize(float min, float max, float val); */ double getAngle (const double p0[3], const double p1[3], const double p2[3]); -/** - * 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. - */ -double calcTetrahedronVolume(const double* x1, const double* x2, const double* x3, const double* x4); /** * simple power function that takes as a second argument an integer instead of a float diff --git a/MeshLib/Elements/TemplateHex-impl.h b/MeshLib/Elements/TemplateHex-impl.h index a88e1f9d504c25a7b2660aceb9c5306ee6e9bea2..45e123cbd9c0e5004337beeb2bfe463f77b4e054 100644 --- a/MeshLib/Elements/TemplateHex-impl.h +++ b/MeshLib/Elements/TemplateHex-impl.h @@ -18,7 +18,7 @@ #include "Quad.h" #include "Prism.h" -#include "MathTools.h" +#include "AnalyticalGeometry.h" namespace MeshLib { @@ -105,12 +105,12 @@ TemplateHex<NNODES,CELLHEXTYPE>::~TemplateHex() template <unsigned NNODES, CellType CELLHEXTYPE> double TemplateHex<NNODES,CELLHEXTYPE>::computeVolume() { - return MathLib::calcTetrahedronVolume(_nodes[4]->getCoords(), _nodes[7]->getCoords(), _nodes[5]->getCoords(), _nodes[0]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[3]->getCoords(), _nodes[1]->getCoords(), _nodes[0]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[7]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[7]->getCoords(), _nodes[6]->getCoords(), _nodes[2]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[1]->getCoords(), _nodes[3]->getCoords(), _nodes[5]->getCoords(), _nodes[2]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[3]->getCoords(), _nodes[7]->getCoords(), _nodes[5]->getCoords(), _nodes[2]->getCoords()); + return GeoLib::calcTetrahedronVolume(_nodes[4]->getCoords(), _nodes[7]->getCoords(), _nodes[5]->getCoords(), _nodes[0]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[3]->getCoords(), _nodes[1]->getCoords(), _nodes[0]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[7]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[5]->getCoords(), _nodes[7]->getCoords(), _nodes[6]->getCoords(), _nodes[2]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[1]->getCoords(), _nodes[3]->getCoords(), _nodes[5]->getCoords(), _nodes[2]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[3]->getCoords(), _nodes[7]->getCoords(), _nodes[5]->getCoords(), _nodes[2]->getCoords()); } template <unsigned NNODES, CellType CELLHEXTYPE> diff --git a/MeshLib/Elements/TemplatePrism-impl.h b/MeshLib/Elements/TemplatePrism-impl.h index 3029b24043788017370fa7653562f427b70547bf..a91d0a2e3c7e2459008a38401187aa1bc86d92b5 100644 --- a/MeshLib/Elements/TemplatePrism-impl.h +++ b/MeshLib/Elements/TemplatePrism-impl.h @@ -20,7 +20,7 @@ #include "Pyramid.h" #include "Quad.h" -#include "MathTools.h" +#include "AnalyticalGeometry.h" namespace MeshLib { @@ -104,9 +104,9 @@ TemplatePrism<NNODES,CELLPRISMTYPE>::~TemplatePrism() template <unsigned NNODES, CellType CELLPRISMTYPE> double TemplatePrism<NNODES,CELLPRISMTYPE>::computeVolume() { - return MathLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[1]->getCoords(), _nodes[4]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[2]->getCoords(), _nodes[4]->getCoords(), _nodes[5]->getCoords(), _nodes[3]->getCoords()); + return GeoLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[1]->getCoords(), _nodes[4]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[2]->getCoords(), _nodes[4]->getCoords(), _nodes[5]->getCoords(), _nodes[3]->getCoords()); } template <unsigned NNODES, CellType CELLPRISMTYPE> diff --git a/MeshLib/Elements/TemplatePyramid-impl.h b/MeshLib/Elements/TemplatePyramid-impl.h index 4a93bab8bfc9a1e3404e64082ebbd0ef6bdc28d5..5bcdd4d0ac21eae981d7bdac57cc90459ce780e7 100644 --- a/MeshLib/Elements/TemplatePyramid-impl.h +++ b/MeshLib/Elements/TemplatePyramid-impl.h @@ -20,7 +20,7 @@ #include "Tet.h" #include "Quad.h" -#include "MathTools.h" +#include "AnalyticalGeometry.h" namespace MeshLib { @@ -107,8 +107,8 @@ TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::~TemplatePyramid() template <unsigned NNODES, CellType CELLPYRAMIDTYPE> double TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::computeVolume() { - return MathLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[4]->getCoords()) - + MathLib::calcTetrahedronVolume(_nodes[2]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords(), _nodes[4]->getCoords()); + return GeoLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[4]->getCoords()) + + GeoLib::calcTetrahedronVolume(_nodes[2]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords(), _nodes[4]->getCoords()); } template <unsigned NNODES, CellType CELLPYRAMIDTYPE> diff --git a/MeshLib/Elements/TemplateTet-impl.h b/MeshLib/Elements/TemplateTet-impl.h index 37a06afed399c9edffd91523583ba8a435aaa3e5..0f9b967dec8d05580ca9d7c3b891307a15328d7f 100644 --- a/MeshLib/Elements/TemplateTet-impl.h +++ b/MeshLib/Elements/TemplateTet-impl.h @@ -17,7 +17,7 @@ #include "Node.h" #include "Tri.h" -#include "MathTools.h" +#include "AnalyticalGeometry.h" namespace MeshLib { @@ -99,7 +99,7 @@ TemplateTet<NNODES,CELLTETTYPE>::~TemplateTet() template <unsigned NNODES, CellType CELLTETTYPE> double TemplateTet<NNODES,CELLTETTYPE>::computeVolume() { - return MathLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()); + return GeoLib::calcTetrahedronVolume(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords(), _nodes[3]->getCoords()); } template <unsigned NNODES, CellType CELLTETTYPE>