6#include <Eigen/Geometry>
20 Eigen::Vector3d
const w =
p.asEigenVector3d() - c.asEigenVector3d();
21 return u.cross(
v).dot(w);
32 return std::abs(
u.cross(
v).dot(w)) / 6.0;
40 Eigen::Vector3d
const w =
u.cross(
v);
41 return 0.5 * w.norm();
50 if (std::abs(d0) > std::numeric_limits<double>::epsilon())
52 bool const d0_sign(d0 > 0);
55 if (!(d0_sign == (d1 >= 0) || std::abs(d1) < eps))
61 if (!(d0_sign == (d2 >= 0) || std::abs(d2) < eps))
67 if (!(d0_sign == (d3 >= 0) || std::abs(d3) < eps))
73 return d0_sign == (d4 >= 0) || std::abs(d4) < eps;
82 double eps_pnt_out_of_plane,
83 double eps_pnt_out_of_tri,
95 ERR(
"Selected algorithm for point in triangle testing not found, "
96 "falling back on default.");
106 double eps_pnt_out_of_plane,
107 double eps_pnt_out_of_tri)
111 Eigen::Vector3d
const w = c.asEigenVector3d() - pa;
114 mat(0, 0) =
v.squaredNorm();
115 mat(0, 1) =
v[0] * w[0] +
v[1] * w[1] +
v[2] * w[2];
116 mat(1, 0) = mat(0, 1);
117 mat(1, 1) = w.squaredNorm();
119 v[0] * (
q[0] - a[0]) +
v[1] * (
q[1] - a[1]) +
v[2] * (
q[2] - a[2]),
120 w[0] * (
q[0] - a[0]) + w[1] * (
q[1] - a[1]) + w[2] * (
q[2] - a[2]));
122 y = mat.partialPivLu().solve(y);
124 const double lower(eps_pnt_out_of_tri);
125 const double upper(1 + lower);
127 if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper &&
128 y[0] + y[1] <= upper)
131 {a[0] + y[0] *
v[0] + y[1] * w[0], a[1] + y[0] *
v[1] + y[1] * w[1],
132 a[2] + y[0] *
v[2] + y[1] * w[2]}});
146 double eps_pnt_out_of_plane,
147 double eps_pnt_out_of_tri)
154 auto const& vp =
p.asEigenVector3d();
157 Eigen::Vector3d
const& pc = c.asEigenVector3d() - vp;
160 double const alpha((pb.cross(pc).norm()) / area_x_2);
161 if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
165 double const beta((pc.cross(pa).norm()) / area_x_2);
166 if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
170 double const gamma(1 - alpha - beta);
171 return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri);
181 mat(0, 0) = b[0] - a[0];
182 mat(0, 1) = c[0] - a[0];
183 mat(1, 0) = b[1] - a[1];
184 mat(1, 1) = c[1] - a[1];
186 y <<
p[0] - a[0],
p[1] - a[1];
188 y = mat.partialPivLu().solve(y);
191 return 0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1;
197 for (
unsigned x = 0; x < 3; ++x)
199 const unsigned y = (x + 1) % 3;
201 (b[x] - a[x]) * (c[y] - a[y]) - (b[y] - a[y]) * (c[x] - a[x]);
203 (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]);
205 if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0))
220 auto const eps_squared =
221 std::pow(std::numeric_limits<double>::epsilon(), 2);
222 if (ab.squaredNorm() < eps_squared || ac.squaredNorm() < eps_squared ||
223 ad.squaredNorm() < eps_squared)
230 const double sqr_scalar_triple(std::pow(ac.cross(ad).dot(ab), 2));
233 const double normalisation_factor =
234 (ab.squaredNorm() * ac.squaredNorm() * ad.squaredNorm());
241 return (sqr_scalar_triple / normalisation_factor < 1e-11);
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Eigen::Vector3d const & asEigenVector3d() const
double orientation3d(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
bool gaussPointInTriangle(MathLib::Point3d const &q, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)
double calcTriangleArea(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
bool isCoplanar(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
Checks if the four given points are located on a plane.
bool dividedByPlane(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
bool isPointInTriangle(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri, MathLib::TriangleTest algorithm)
bool barycentricPointInTriangle(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
double calcTetrahedronVolume(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d)
bool isPointInTetrahedron(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d, double eps)
bool isPointInTriangleXY(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)