diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 0f01711e2e15a477909d14e6f639f140c6241f4c..24e79ccc823e16834fbb81f81d36ab05cb293178 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -288,31 +288,37 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( MathLib::Point3d const& c, MathLib::Point3d const& p, MathLib::Point3d const& q) { - const MathLib::Vector3 pq(p, q); - const MathLib::Vector3 pa(p, a); - const MathLib::Vector3 pb(p, b); - const MathLib::Vector3 pc(p, c); - - double u (MathLib::scalarTriple(pq, pc, pb)); + auto const va = Eigen::Map<Eigen::Vector3d const>(a.getCoords()); + auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords()); + auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords()); + auto const vp = Eigen::Map<Eigen::Vector3d const>(p.getCoords()); + auto const vq = Eigen::Map<Eigen::Vector3d const>(q.getCoords()); + + Eigen::Vector3d const pq = vq - vp; + Eigen::Vector3d const pa = va - vp; + Eigen::Vector3d const pb = vb - vp; + Eigen::Vector3d const pc = vc - vp; + + double u(MathLib::scalarTriple(pq, pc, pb)); if (u < 0) { return nullptr; } - double v (MathLib::scalarTriple(pq, pa, pc)); + double v(MathLib::scalarTriple(pq, pa, pc)); if (v < 0) { return nullptr; } - double w (MathLib::scalarTriple(pq, pb, pa)); + double w(MathLib::scalarTriple(pq, pb, pa)); if (w < 0) { return nullptr; } - const double denom (1.0/(u+v+w)); - u*=denom; - v*=denom; - w*=denom; + const double denom(1.0 / (u + v + w)); + u *= denom; + v *= denom; + w *= denom; return std::make_unique<GeoLib::Point>(u * a[0] + v * b[0] + w * c[0], u * a[1] + v * b[1] + w * c[1], u * a[2] + v * b[2] + w * c[2]); diff --git a/GeoLib/MinimalBoundingSphere.cpp b/GeoLib/MinimalBoundingSphere.cpp index 7f99bc9f6072bed483c9baa62f13da3f5751bdec..0986bc90dd12ea9ec421096ce05a4d3f4c0fc843 100644 --- a/GeoLib/MinimalBoundingSphere.cpp +++ b/GeoLib/MinimalBoundingSphere.cpp @@ -18,7 +18,7 @@ #include "MathLib/Point3d.h" #include "MathLib/GeometricBasics.h" -#include "MathLib/Vector3.h" +#include "MathLib/MathTools.h" namespace GeoLib { MinimalBoundingSphere::MinimalBoundingSphere() = default; @@ -81,13 +81,25 @@ MinimalBoundingSphere::MinimalBoundingSphere(MathLib::Point3d const& p, MathLib::Point3d const& r, MathLib::Point3d const& s) { + auto const vp = + Eigen::Map<Eigen::Vector3d>(const_cast<double*>(p.getCoords())); + auto const vq = + Eigen::Map<Eigen::Vector3d>(const_cast<double*>(q.getCoords())); + auto const vr = + Eigen::Map<Eigen::Vector3d>(const_cast<double*>(r.getCoords())); + auto const vs = + Eigen::Map<Eigen::Vector3d>(const_cast<double*>(s.getCoords())); + + Eigen::Vector3d const va = vq - vp; + Eigen::Vector3d const vb = vr - vp; + Eigen::Vector3d const vc = vs - vp; MathLib::Vector3 const a(p, q); MathLib::Vector3 const b(p, r); MathLib::Vector3 const c(p, s); if (!MathLib::isCoplanar(p, q, r, s)) { - double const denom = 2.0 * MathLib::scalarTriple(a,b,c); + double const denom = 2.0 * MathLib::scalarTriple(va, vb, vc); MathLib::Vector3 const o = (scalarProduct(c,c) * crossProduct(a,b) + scalarProduct(b,b) * crossProduct(c,a) + scalarProduct(a,a) * crossProduct(b,c)) diff --git a/MathLib/GeometricBasics.cpp b/MathLib/GeometricBasics.cpp index 8fd6bc43dc9d74bde74c5b47e5ca4c4b0701e94d..a9dbc23e341a251974e117b4b8da486c1728041a 100644 --- a/MathLib/GeometricBasics.cpp +++ b/MathLib/GeometricBasics.cpp @@ -23,10 +23,15 @@ double orientation3d(MathLib::Point3d const& p, MathLib::Point3d const& b, MathLib::Point3d const& c) { - MathLib::Vector3 const ap (a, p); - MathLib::Vector3 const bp (b, p); - MathLib::Vector3 const cp (c, p); - return MathLib::scalarTriple(bp,cp,ap); + auto const pp = Eigen::Map<Eigen::Vector3d const>(p.getCoords()); + auto const pa = Eigen::Map<Eigen::Vector3d const>(a.getCoords()); + auto const pb = Eigen::Map<Eigen::Vector3d const>(b.getCoords()); + auto const pc = Eigen::Map<Eigen::Vector3d const>(c.getCoords()); + + Eigen::Vector3d const ap = pp - pa; + Eigen::Vector3d const bp = pp - pb; + Eigen::Vector3d const cp = pp - pc; + return MathLib::scalarTriple(bp, cp, ap); } double calcTetrahedronVolume(MathLib::Point3d const& a, @@ -34,9 +39,13 @@ double calcTetrahedronVolume(MathLib::Point3d const& a, MathLib::Point3d const& c, MathLib::Point3d const& d) { - const MathLib::Vector3 ab(a, b); - const MathLib::Vector3 ac(a, c); - const MathLib::Vector3 ad(a, d); + auto const va = Eigen::Map<Eigen::Vector3d const>(a.getCoords()); + auto const vb = Eigen::Map<Eigen::Vector3d const>(b.getCoords()); + auto const vc = Eigen::Map<Eigen::Vector3d const>(c.getCoords()); + auto const vd = Eigen::Map<Eigen::Vector3d const>(d.getCoords()); + Eigen::Vector3d const ab = vb - va; + Eigen::Vector3d const ac = vc - va; + Eigen::Vector3d const ad = vd - va; return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0; }