12#include <Eigen/Geometry>
26 Eigen::Vector3d
const w =
p.asEigenVector3d() - c.asEigenVector3d();
27 return u.cross(
v).dot(w);
38 return std::abs(
u.cross(
v).dot(w)) / 6.0;
46 Eigen::Vector3d
const w =
u.cross(
v);
47 return 0.5 * w.norm();
56 if (std::abs(d0) > std::numeric_limits<double>::epsilon())
58 bool const d0_sign(d0 > 0);
61 if (!(d0_sign == (d1 >= 0) || std::abs(d1) < eps))
67 if (!(d0_sign == (d2 >= 0) || std::abs(d2) < eps))
73 if (!(d0_sign == (d3 >= 0) || std::abs(d3) < eps))
79 return d0_sign == (d4 >= 0) || std::abs(d4) < eps;
88 double eps_pnt_out_of_plane,
89 double eps_pnt_out_of_tri,
101 ERR(
"Selected algorithm for point in triangle testing not found, "
102 "falling back on default.");
112 double eps_pnt_out_of_plane,
113 double eps_pnt_out_of_tri)
117 Eigen::Vector3d
const w = c.asEigenVector3d() - pa;
120 mat(0, 0) =
v.squaredNorm();
121 mat(0, 1) =
v[0] * w[0] +
v[1] * w[1] +
v[2] * w[2];
122 mat(1, 0) = mat(0, 1);
123 mat(1, 1) = w.squaredNorm();
125 v[0] * (
q[0] - a[0]) +
v[1] * (
q[1] - a[1]) +
v[2] * (
q[2] - a[2]),
126 w[0] * (
q[0] - a[0]) + w[1] * (
q[1] - a[1]) + w[2] * (
q[2] - a[2]));
128 y = mat.partialPivLu().solve(y);
130 const double lower(eps_pnt_out_of_tri);
131 const double upper(1 + lower);
133 if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper &&
134 y[0] + y[1] <= upper)
137 {a[0] + y[0] *
v[0] + y[1] * w[0], a[1] + y[0] *
v[1] + y[1] * w[1],
138 a[2] + y[0] *
v[2] + y[1] * w[2]}});
152 double eps_pnt_out_of_plane,
153 double eps_pnt_out_of_tri)
160 auto const& vp =
p.asEigenVector3d();
163 Eigen::Vector3d
const& pc = c.asEigenVector3d() - vp;
166 double const alpha((pb.cross(pc).norm()) / area_x_2);
167 if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
171 double const beta((pc.cross(pa).norm()) / area_x_2);
172 if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
176 double const gamma(1 - alpha - beta);
177 return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri);
187 mat(0, 0) = b[0] - a[0];
188 mat(0, 1) = c[0] - a[0];
189 mat(1, 0) = b[1] - a[1];
190 mat(1, 1) = c[1] - a[1];
192 y <<
p[0] - a[0],
p[1] - a[1];
194 y = mat.partialPivLu().solve(y);
197 return 0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1;
203 for (
unsigned x = 0; x < 3; ++x)
205 const unsigned y = (x + 1) % 3;
207 (b[x] - a[x]) * (c[y] - a[y]) - (b[y] - a[y]) * (c[x] - a[x]);
209 (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]);
211 if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0))
226 auto const eps_squared =
227 std::pow(std::numeric_limits<double>::epsilon(), 2);
228 if (ab.squaredNorm() < eps_squared || ac.squaredNorm() < eps_squared ||
229 ad.squaredNorm() < eps_squared)
236 const double sqr_scalar_triple(std::pow(ac.cross(ad).dot(ab), 2));
239 const double normalisation_factor =
240 (ab.squaredNorm() * ac.squaredNorm() * ad.squaredNorm());
247 return (sqr_scalar_triple / normalisation_factor < 1e-11);
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Point3d class.
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)