From 52f57160aab79cf3b4dc0973aa9c0d69f48be736 Mon Sep 17 00:00:00 2001 From: frohlich Date: Thu, 15 Jun 2006 19:13:24 +0000 Subject: [PATCH] Add dist and distSqr functions --- simgear/math/SGVec3.hxx | 14 ++++++++++++++ simgear/math/SGVec4.hxx | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/simgear/math/SGVec3.hxx b/simgear/math/SGVec3.hxx index b08e18f7..e6ea50aa 100644 --- a/simgear/math/SGVec3.hxx +++ b/simgear/math/SGVec3.hxx @@ -296,6 +296,20 @@ equivalent(const SGVec3& v1, const SGVec3& v2) return equivalent(v1, v2, tol, tol); } +/// The euclidean distance of the two vectors +template +inline +T +dist(const SGVec3& v1, const SGVec3& v2) +{ return norm(v1 - v2); } + +/// The squared euclidean distance of the two vectors +template +inline +T +distSqr(const SGVec3& v1, const SGVec3& v2) +{ SGVec3 tmp = v1 - v2; return dot(tmp, tmp); } + #ifndef NDEBUG template inline diff --git a/simgear/math/SGVec4.hxx b/simgear/math/SGVec4.hxx index b8c78050..9df380d7 100644 --- a/simgear/math/SGVec4.hxx +++ b/simgear/math/SGVec4.hxx @@ -248,6 +248,20 @@ equivalent(const SGVec4& v1, const SGVec4& v2) return equivalent(v1, v2, tol, tol); } +/// The euclidean distance of the two vectors +template +inline +T +dist(const SGVec4& v1, const SGVec4& v2) +{ return norm(v1 - v2); } + +/// The squared euclidean distance of the two vectors +template +inline +T +distSqr(const SGVec4& v1, const SGVec4& v2) +{ SGVec4 tmp = v1 - v2; return dot(tmp, tmp); } + #ifndef NDEBUG template inline -- 2.39.5