diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp index 469c3ab0c033277b4801001d51c403e2bb701f45..bf421e98986b47c2e62e87fb7617d5af0360a3b6 100644 --- a/MathLib/MathTools.cpp +++ b/MathLib/MathTools.cpp @@ -42,13 +42,17 @@ double calcProjPntToLineAndDists(Point3d const& pp, Point3d const& pa, return (p - proj_pnt).norm(); } -double getAngle (const double p0[3], const double p1[3], const double p2[3]) +double getAngle(Point3d const& p0, Point3d const& p1, Point3d const& p2) { - const double v0[3] = {p0[0]-p1[0], p0[1]-p1[1], p0[2]-p1[2]}; - const double v1[3] = {p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2]}; + auto const a = Eigen::Map<Eigen::Vector3d const>(p0.getCoords()); + auto const b = Eigen::Map<Eigen::Vector3d const>(p1.getCoords()); + auto const c = Eigen::Map<Eigen::Vector3d const>(p2.getCoords()); + Eigen::Vector3d const v0 = a - b; + Eigen::Vector3d const v1 = c - b; // apply Cauchy Schwarz inequality - return std::acos (scalarProduct<double,3> (v0,v1) / (std::sqrt(scalarProduct<double,3>(v0,v0)) * sqrt(scalarProduct<double,3>(v1,v1)))); + return std::acos( + (v0.transpose() * v1 / (v0.norm() * v1.norm()))(0, 0)); } double scalarTriple(Eigen::Vector3d const& u, Eigen::Vector3d const& v, diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 6018091a454ec1fa979adb89e82e32935504f0eb..699d3ff7225ed3ea8c2368d25c29b90ad54060d2 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -90,7 +90,7 @@ double calcProjPntToLineAndDists(MathLib::Point3d const& pp, * @param p2 end point of edge 1 * @return the angle between the edges */ -double getAngle (const double p0[3], const double p1[3], const double p2[3]); +double getAngle(Point3d const& p0, Point3d const& p1, Point3d const& p2); /// Calculates the scalar triple (u x v) . w double scalarTriple(Eigen::Vector3d const& u, Eigen::Vector3d const& v,