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

[GL] Substitute MaL::Vector3 by Eigen::Vector3d.

parent cabff25b
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <Eigen/Dense> #include <Eigen/Dense>
#include "Point3d.h" #include "Point3d.h"
#include "Vector3.h"
#include "GeometricBasics.h" #include "GeometricBasics.h"
...@@ -28,10 +27,10 @@ double orientation3d(MathLib::Point3d const& p, ...@@ -28,10 +27,10 @@ double orientation3d(MathLib::Point3d const& p,
auto const pb = Eigen::Map<Eigen::Vector3d const>(b.getCoords()); auto const pb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
auto const pc = Eigen::Map<Eigen::Vector3d const>(c.getCoords()); auto const pc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
Eigen::Vector3d const ap = pp - pa; Eigen::Vector3d const u = pp - pa;
Eigen::Vector3d const bp = pp - pb; Eigen::Vector3d const v = pp - pb;
Eigen::Vector3d const cp = pp - pc; Eigen::Vector3d const w = pp - pc;
return MathLib::scalarTriple(bp, cp, ap); return u.cross(v).dot(w);
} }
double calcTetrahedronVolume(MathLib::Point3d const& a, double calcTetrahedronVolume(MathLib::Point3d const& a,
...@@ -43,19 +42,22 @@ double calcTetrahedronVolume(MathLib::Point3d const& a, ...@@ -43,19 +42,22 @@ double calcTetrahedronVolume(MathLib::Point3d const& a,
auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords()); auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords()); auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
auto const vd = Eigen::Map<Eigen::Vector3d const>(d.getCoords()); auto const vd = Eigen::Map<Eigen::Vector3d const>(d.getCoords());
Eigen::Vector3d const ab = vb - va; Eigen::Vector3d const w = vb - va;
Eigen::Vector3d const ac = vc - va; Eigen::Vector3d const u = vc - va;
Eigen::Vector3d const ad = vd - va; Eigen::Vector3d const v = vd - va;
return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0; return std::abs(u.cross(v).dot(w)) / 6.0;
} }
double calcTriangleArea(MathLib::Point3d const& a, MathLib::Point3d const& b, double calcTriangleArea(MathLib::Point3d const& a, MathLib::Point3d const& b,
MathLib::Point3d const& c) MathLib::Point3d const& c)
{ {
MathLib::Vector3 const u(a, c); auto const va = Eigen::Map<Eigen::Vector3d const>(a.getCoords());
MathLib::Vector3 const v(a, b); auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
MathLib::Vector3 const w(MathLib::crossProduct(u, v)); auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
return 0.5 * w.getLength(); Eigen::Vector3d const u = vc - va;
Eigen::Vector3d const v = vb - va;
Eigen::Vector3d const w = u.cross(v);
return 0.5 * w.norm();
} }
bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a, bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a,
...@@ -123,17 +125,20 @@ bool gaussPointInTriangle(MathLib::Point3d const& q, ...@@ -123,17 +125,20 @@ bool gaussPointInTriangle(MathLib::Point3d const& q,
double eps_pnt_out_of_plane, double eps_pnt_out_of_plane,
double eps_pnt_out_of_tri) double eps_pnt_out_of_tri)
{ {
MathLib::Vector3 const v(a, b); auto const pa = Eigen::Map<Eigen::Vector3d const>(a.getCoords());
MathLib::Vector3 const w(a, c); auto const pb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
auto const pc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
Eigen::Vector3d const v = pb - pa;
Eigen::Vector3d const w = pc - pa;
Eigen::Matrix2d mat; Eigen::Matrix2d mat;
mat(0, 0) = v.getSqrLength(); mat(0, 0) = v.squaredNorm();
mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2]; mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2];
mat(1, 0) = mat(0, 1); mat(1, 0) = mat(0, 1);
mat(1, 1) = w.getSqrLength(); mat(1, 1) = w.squaredNorm();
Eigen::Vector2d y; Eigen::Vector2d y(
y << v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]), v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]),
w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2]); w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2]));
y = mat.partialPivLu().solve(y); y = mat.partialPivLu().solve(y);
...@@ -167,17 +172,21 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, ...@@ -167,17 +172,21 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
return false; return false;
} }
MathLib::Vector3 const pa(p, a); auto const vp = Eigen::Map<Eigen::Vector3d const>(p.getCoords());
MathLib::Vector3 const pb(p, b); auto const va = Eigen::Map<Eigen::Vector3d const>(a.getCoords());
MathLib::Vector3 const pc(p, c); auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
Eigen::Vector3d const pa = va - vp;
Eigen::Vector3d const pb = vb - vp;
Eigen::Vector3d const pc = vc - vp;
double const area_x_2(calcTriangleArea(a, b, c) * 2); double const area_x_2(calcTriangleArea(a, b, c) * 2);
double const alpha((MathLib::crossProduct(pb, pc).getLength()) / area_x_2); double const alpha((pb.cross(pc).norm()) / area_x_2);
if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri) if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
{ {
return false; return false;
} }
double const beta((MathLib::crossProduct(pc, pa).getLength()) / area_x_2); double const beta((pc.cross(pa).norm()) / area_x_2);
if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri) if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
{ {
return false; return false;
...@@ -228,25 +237,30 @@ bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b, ...@@ -228,25 +237,30 @@ bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b,
bool isCoplanar(const MathLib::Point3d& a, const MathLib::Point3d& b, bool isCoplanar(const MathLib::Point3d& a, const MathLib::Point3d& b,
const MathLib::Point3d& c, const MathLib::Point3d& d) const MathLib::Point3d& c, const MathLib::Point3d& d)
{ {
const MathLib::Vector3 ab(a, b); auto const pa = Eigen::Map<Eigen::Vector3d const>(a.getCoords());
const MathLib::Vector3 ac(a, c); auto const pb = Eigen::Map<Eigen::Vector3d const>(b.getCoords());
const MathLib::Vector3 ad(a, d); auto const pc = Eigen::Map<Eigen::Vector3d const>(c.getCoords());
auto const pd = Eigen::Map<Eigen::Vector3d const>(d.getCoords());
Eigen::Vector3d const ab = pb - pa;
Eigen::Vector3d const ac = pc - pa;
Eigen::Vector3d const ad = pd - pa;
if (ab.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) || auto const eps_squared =
ac.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) || std::pow(std::numeric_limits<double>::epsilon(), 2);
ad.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2)) if (ab.squaredNorm() < eps_squared || ac.squaredNorm() < eps_squared ||
ad.squaredNorm() < eps_squared)
{ {
return true; return true;
} }
// In exact arithmetic <ac*ad^T, ab> should be zero // In exact arithmetic <ac*ad^T, ab> should be zero
// if all four points are coplanar. // if all four points are coplanar.
const double sqr_scalar_triple( const double sqr_scalar_triple(std::pow(ac.cross(ad).dot(ab), 2));
pow(MathLib::scalarProduct(MathLib::crossProduct(ac, ad), ab), 2));
// Due to evaluating the above numerically some cancellation or rounding // Due to evaluating the above numerically some cancellation or rounding
// can occur. For this reason a normalisation factor is introduced. // can occur. For this reason a normalisation factor is introduced.
const double normalisation_factor = const double normalisation_factor =
(ab.getSqrLength() * ac.getSqrLength() * ad.getSqrLength()); (ab.squaredNorm() * ac.squaredNorm() * ad.squaredNorm());
// tolerance 1e-11 is choosen such that // tolerance 1e-11 is choosen such that
// a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as // a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as
......
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