12 #include <Eigen/Dense>
24 auto const pp = Eigen::Map<Eigen::Vector3d const>(
p.getCoords());
25 auto const pa = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
26 auto const pb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
27 auto const pc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
29 Eigen::Vector3d
const u = pp - pa;
30 Eigen::Vector3d
const v = pp - pb;
31 Eigen::Vector3d
const w = pp - pc;
32 return u.cross(v).dot(w);
40 auto const va = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
41 auto const vb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
42 auto const vc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
43 auto const vd = Eigen::Map<Eigen::Vector3d const>(d.
getCoords());
44 Eigen::Vector3d
const w = vb - va;
45 Eigen::Vector3d
const u = vc - va;
46 Eigen::Vector3d
const v = vd - va;
47 return std::abs(u.cross(v).dot(w)) / 6.0;
53 auto const va = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
54 auto const vb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
55 auto const vc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
56 Eigen::Vector3d
const u = vc - va;
57 Eigen::Vector3d
const v = vb - va;
58 Eigen::Vector3d
const w = u.cross(v);
59 return 0.5 * w.norm();
68 if (std::abs(d0) > std::numeric_limits<double>::epsilon())
70 bool const d0_sign(d0 > 0);
73 if (!(d0_sign == (d1 >= 0) || std::abs(d1) < eps))
79 if (!(d0_sign == (d2 >= 0) || std::abs(d2) < eps))
85 if (!(d0_sign == (d3 >= 0) || std::abs(d3) < eps))
91 return d0_sign == (d4 >= 0) || std::abs(d4) < eps;
100 double eps_pnt_out_of_plane,
101 double eps_pnt_out_of_tri,
113 ERR(
"Selected algorithm for point in triangle testing not found, "
114 "falling back on default.");
124 double eps_pnt_out_of_plane,
125 double eps_pnt_out_of_tri)
127 auto const pa = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
128 auto const pb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
129 auto const pc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
130 Eigen::Vector3d
const v = pb - pa;
131 Eigen::Vector3d
const w = pc - pa;
134 mat(0, 0) = v.squaredNorm();
135 mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2];
136 mat(1, 0) = mat(0, 1);
137 mat(1, 1) = w.squaredNorm();
139 v[0] * (
q[0] - a[0]) + v[1] * (
q[1] - a[1]) + v[2] * (
q[2] - a[2]),
140 w[0] * (
q[0] - a[0]) + w[1] * (
q[1] - a[1]) + w[2] * (
q[2] - a[2]));
142 y = mat.partialPivLu().solve(y);
144 const double lower(eps_pnt_out_of_tri);
145 const double upper(1 + lower);
147 if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper &&
148 y[0] + y[1] <= upper)
151 {a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1],
152 a[2] + y[0] * v[2] + y[1] * w[2]}});
166 double eps_pnt_out_of_plane,
167 double eps_pnt_out_of_tri)
174 auto const vp = Eigen::Map<Eigen::Vector3d const>(
p.getCoords());
175 auto const va = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
176 auto const vb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
177 auto const vc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
178 Eigen::Vector3d
const pa = va - vp;
179 Eigen::Vector3d
const pb = vb - vp;
180 Eigen::Vector3d
const pc = vc - vp;
183 double const alpha((pb.cross(pc).norm()) / area_x_2);
184 if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
188 double const beta((pc.cross(pa).norm()) / area_x_2);
189 if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
194 return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri);
204 mat(0, 0) = b[0] - a[0];
205 mat(0, 1) =
c[0] - a[0];
206 mat(1, 0) = b[1] - a[1];
207 mat(1, 1) =
c[1] - a[1];
209 y <<
p[0] - a[0],
p[1] - a[1];
211 y = mat.partialPivLu().solve(y);
214 return 0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1;
220 for (
unsigned x = 0; x < 3; ++x)
222 const unsigned y = (x + 1) % 3;
224 (b[x] - a[x]) * (
c[y] - a[y]) - (b[y] - a[y]) * (
c[x] - a[x]);
226 (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]);
228 if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0))
239 auto const pa = Eigen::Map<Eigen::Vector3d const>(a.
getCoords());
240 auto const pb = Eigen::Map<Eigen::Vector3d const>(b.
getCoords());
241 auto const pc = Eigen::Map<Eigen::Vector3d const>(
c.getCoords());
242 auto const pd = Eigen::Map<Eigen::Vector3d const>(d.
getCoords());
244 Eigen::Vector3d
const ab = pb - pa;
245 Eigen::Vector3d
const ac = pc - pa;
246 Eigen::Vector3d
const ad = pd - pa;
248 auto const eps_squared =
249 std::pow(std::numeric_limits<double>::epsilon(), 2);
250 if (ab.squaredNorm() < eps_squared || ac.squaredNorm() < eps_squared ||
251 ad.squaredNorm() < eps_squared)
258 const double sqr_scalar_triple(std::pow(ac.cross(ad).dot(ab), 2));
261 const double normalisation_factor =
262 (ab.squaredNorm() * ac.squaredNorm() * ad.squaredNorm());
269 return (sqr_scalar_triple / normalisation_factor < 1e-11);
void ERR(char const *fmt, Args const &... args)
Definition of the Point3d class.
const T * getCoords() 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)