From e1f3b216866bea0dcd77cb33133928c989045c33 Mon Sep 17 00:00:00 2001 From: Gerardo Tauriello <gerardo.tauriello@unibas.ch> Date: Tue, 14 Jun 2016 19:59:55 +0200 Subject: [PATCH] Inlined DihedralAngle and ensured Real-ops used for increased performance. --- modules/geom/src/vecmat3_op.cc | 14 -------------- modules/geom/src/vecmat3_op.hh | 13 ++++++++++--- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/modules/geom/src/vecmat3_op.cc b/modules/geom/src/vecmat3_op.cc index 3c5cbdea2..f476eca30 100644 --- a/modules/geom/src/vecmat3_op.cc +++ b/modules/geom/src/vecmat3_op.cc @@ -178,20 +178,6 @@ Mat3 AxisRotation(const Vec3& axis, Real angle) xy-ca*xy+sa*z, yy+ca-ca*yy, yz-ca*yz-sa*x, xz-ca*xz-sa*y, yz-ca*yz+sa*x,zz+ca-ca*zz); } - - -Real DihedralAngle(const Vec3& p1, const Vec3& p2, const Vec3& p3, - const Vec3&p4) -{ - Vec3 r1=p2-p1; - Vec3 r2=p3-p2; - Vec3 r3=p4-p3; - Vec3 r12cross = Cross(r1, r2); - Vec3 r23cross = Cross(r2, r3); - return atan2(Dot(r1*Length(r2), r23cross), - Dot(r12cross, r23cross)); -} - Real MinDistance(const Vec3List& l1, const Vec3List& l2) { diff --git a/modules/geom/src/vecmat3_op.hh b/modules/geom/src/vecmat3_op.hh index fbaaec161..d7762cccf 100644 --- a/modules/geom/src/vecmat3_op.hh +++ b/modules/geom/src/vecmat3_op.hh @@ -166,9 +166,16 @@ Mat3 DLLEXPORT_OST_GEOM AxisRotation(const Vec3& axis, Real angle); /// The returned vector is of length 1 Vec3 DLLEXPORT_OST_GEOM OrthogonalVector(const Vec3& axis); - -Real DLLEXPORT_OST_GEOM DihedralAngle(const Vec3& p1, const Vec3& p2, - const Vec3& p3, const Vec3&p4); +/// \brief Get dihedral angle for p1-p2-p3-p4 +inline Real DihedralAngle(const Vec3& p1, const Vec3& p2, + const Vec3& p3, const Vec3& p4) { + const Vec3 r1 = p2-p1; + const Vec3 r2 = p3-p2; + const Vec3 r3 = p4-p3; + const Vec3 r12cross = Cross(r1, r2); + const Vec3 r23cross = Cross(r2, r3); + return std::atan2(Dot(r1*Length(r2), r23cross), Dot(r12cross, r23cross)); +} //! returns std::min of each component inline Vec3 Min(const Vec3& v1, const Vec3& v2) -- GitLab