From 4057a131c83385e967e38a273d9c52c7dbca5505 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 19 Feb 2015 14:20:09 +1100 Subject: [PATCH] line: add closest parameter to point query --- line.cpp | 17 ++++++++++++++--- line.hpp | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) 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;