diff --git a/line.cpp b/line.cpp index 90e66883..c1c84a00 100644 --- a/line.cpp +++ b/line.cpp @@ -34,15 +34,26 @@ util::line::line (util::point _p, ///---------------------------------------------------------------------------- -/// returns the distance alone the line in a line-plane intersection +/// returns the distance along the line in a line-plane intersection /// /// returns inf if parallel /// returns 0 if colinear template T -util::line::intersect (plane rhs) const +util::line::intersect (plane q) const { - return dot (rhs.p - p, rhs.n) / dot (d, rhs.n); + return dot (q.p - p, q.n) / dot (d, q.n); +} + + +///---------------------------------------------------------------------------- +/// returns the closest parameter along the line to a given point +template +T +util::line::closest (point q) const +{ + // project the origin-point difference onto the direction + return dot (p - q, d); } diff --git a/line.hpp b/line.hpp index 3a13b94a..1b5d017d 100644 --- a/line.hpp +++ b/line.hpp @@ -31,6 +31,7 @@ namespace util { util::vector direction); T intersect (plane) const; + T closest (point) const; util::point at (T) const;