From a3bd9a686eb0b385c108be49b0906cfa1820f55d Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 20 Nov 2020 16:59:31 +0100
Subject: [PATCH] [MaL] Use Eigen in getAngle computation.

---
 MathLib/MathTools.cpp | 12 ++++++++----
 MathLib/MathTools.h   |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp
index 469c3ab0c03..bf421e98986 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 6018091a454..699d3ff7225 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,
-- 
GitLab