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

[MaL] Impl. of isPointInTriangleXY().

parent e9a8f4df
No related branches found
No related tags found
No related merge requests found
...@@ -169,6 +169,31 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, ...@@ -169,6 +169,31 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
return true; return true;
} }
bool isPointInTriangleXY(MathLib::Point3d const& p,
MathLib::Point3d const& a,
MathLib::Point3d const& b,
MathLib::Point3d const& c)
{
// criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
MathLib::DenseMatrix<double> mat(2, 2);
mat(0, 0) = b[0] - a[0];
mat(0, 1) = c[0] - a[0];
mat(1, 0) = b[1] - a[1];
mat(1, 1) = c[1] - a[1];
double y[2] = {p[0] - a[0], p[1] - a[1]};
MathLib::GaussAlgorithm<MathLib::DenseMatrix<double>, double*> gauss;
gauss.solve(mat, y, true);
// check if u0 and u1 fulfills the condition
if (0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1)
{
return true;
}
return false;
}
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)
{ {
......
...@@ -154,6 +154,13 @@ bool barycentricPointInTriangle( ...@@ -154,6 +154,13 @@ bool barycentricPointInTriangle(
double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(), double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(),
double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon()); double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon());
/// Checks if the point \f$p'\f$ is in the triangle defined by the points
/// \f$a', b', c'\f$, where the \f$p', a', b', c' \f$ are the orthogonal
/// projections to the \f$x\f$-\f$y\f$ plane of the points \f$p, a, b, c\f$,
/// respectively.
bool isPointInTriangleXY(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 * 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 said plane. (In 2D space this checks if c and d are on different
......
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