]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGRay.hxx
Add closest-point calculation to SGRay, to replace a vector.h helper.
[simgear.git] / simgear / math / SGRay.hxx
index afd7b0413f11d27449e51a0b8f480576cd7959c5..eef28cc46beadbae5ae2582fbddf0e7045fd3d1a 100644 (file)
@@ -47,6 +47,12 @@ public:
   SGVec3<T> getNormalizedDirection() const
   { return normalize(getDirection()); }
 
+  SGVec3<T> getClosestPointTo(const SGVec3<T>& point)
+  {
+      SGVec3<T> u(getNormalizedDirection()),
+          v(point - _origin);
+      return (dot(u, v) * u) + _origin; 
+  }
 private:
   SGVec3<T> _origin;
   SGVec3<T> _direction;