line: add closest parameter to point query

This commit is contained in:
Danny Robson 2015-02-19 14:20:09 +11:00
parent 0ed770eb09
commit 4057a131c8
2 changed files with 15 additions and 3 deletions

View File

@ -34,15 +34,26 @@ util::line<S,T>::line (util::point<S,T> _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 inf if parallel
/// returns 0 if colinear /// returns 0 if colinear
template <size_t S, typename T> template <size_t S, typename T>
T T
util::line<S,T>::intersect (plane<S,T> rhs) const util::line<S,T>::intersect (plane<S,T> 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 <size_t S, typename T>
T
util::line<S,T>::closest (point<S,T> q) const
{
// project the origin-point difference onto the direction
return dot (p - q, d);
} }

View File

@ -31,6 +31,7 @@ namespace util {
util::vector<S,T> direction); util::vector<S,T> direction);
T intersect (plane<S,T>) const; T intersect (plane<S,T>) const;
T closest (point<S,T>) const;
util::point<S,T> at (T) const; util::point<S,T> at (T) const;