Skip to content
Snippets Groups Projects
Commit 4aaa67a0 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MaL/GL] Mv orientation3d from GL to MaL.

parent 09be7267
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "PointVec.h" #include "PointVec.h"
#include "MathLib/LinAlg/Solvers/GaussAlgorithm.h" #include "MathLib/LinAlg/Solvers/GaussAlgorithm.h"
#include "MathLib/GeometricBasics.h"
extern double orient2d(double *, double *, double *); extern double orient2d(double *, double *, double *);
...@@ -300,7 +301,7 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, ...@@ -300,7 +301,7 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
double eps_pnt_out_of_plane, double eps_pnt_out_of_plane,
double eps_pnt_out_of_tri) 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; return false;
MathLib::Vector3 const pa (p,a); MathLib::Vector3 const pa (p,a);
...@@ -324,25 +325,25 @@ bool isPointInTetrahedron(MathLib::Point3d const& p, ...@@ -324,25 +325,25 @@ bool isPointInTetrahedron(MathLib::Point3d const& p,
MathLib::Point3d const& a, MathLib::Point3d const& b, MathLib::Point3d const& a, MathLib::Point3d const& b,
MathLib::Point3d const& c, MathLib::Point3d const& d, double eps) 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 tetrahedron is not coplanar
if (std::abs(d0) > std::numeric_limits<double>::epsilon()) if (std::abs(d0) > std::numeric_limits<double>::epsilon())
{ {
bool const d0_sign (d0>0); bool const d0_sign (d0>0);
// if p is on the same side of bcd as a // 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)) if (!(d0_sign == (d1>=0) || std::abs(d1) < eps))
return false; return false;
// if p is on the same side of acd as b // 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)) if (!(d0_sign == (d2>=0) || std::abs(d2) < eps))
return false; return false;
// if p is on the same side of abd as c // 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)) if (!(d0_sign == (d3>=0) || std::abs(d3) < eps))
return false; return false;
// if p is on the same side of abc as d // 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)) if (!(d0_sign == (d4>=0) || std::abs(d4) < eps))
return false; return false;
return true; return true;
...@@ -439,17 +440,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( ...@@ -439,17 +440,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection(
u * a[2] + v * b[2] + w * c[2])}; 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, bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b,
const MathLib::Point3d& c, const MathLib::Point3d& d) const MathLib::Point3d& c, const MathLib::Point3d& d)
{ {
......
...@@ -316,20 +316,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( ...@@ -316,20 +316,6 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection(
MathLib::Point3d const& c, MathLib::Point3d const& p, MathLib::Point3d const& c, MathLib::Point3d const& p,
MathLib::Point3d const& q); 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. * 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.) * (In 2D space this checks if c and d are on different sides of a line through a and b.)
......
...@@ -14,6 +14,17 @@ ...@@ -14,6 +14,17 @@
namespace MathLib 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, double calcTetrahedronVolume(MathLib::Point3d const& a,
MathLib::Point3d const& b, MathLib::Point3d const& b,
MathLib::Point3d const& c, MathLib::Point3d const& c,
......
...@@ -19,6 +19,23 @@ namespace MathLib ...@@ -19,6 +19,23 @@ namespace MathLib
template <typename T, std::size_t DIM> class TemplatePoint; template <typename T, std::size_t DIM> class TemplatePoint;
typedef MathLib::TemplatePoint<double,3> Point3d; 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. * 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. * The formula is V=1/6*|a(b x c)| with a=x1->x2, b=x1->x3 and c=x1->x4.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment