diff --git a/geom/plane.hpp b/geom/plane.hpp index b87d99b6..689470de 100644 --- a/geom/plane.hpp +++ b/geom/plane.hpp @@ -75,16 +75,31 @@ namespace util::geom { /// calculates the distance from a plane to a point. /// /// positive distances are in front of the plane, negative is behind; + /// + /// NOTE: `distance2` is _not_ the squared distance. It is the + /// unnormalised distance. It needs to be divided by the norm of the + /// plane normal. + template + T + distance2 (plane p, point q) + { + return dot (p.coefficients, q.template redim (1)); + } + + + template + T + distance2 (point p, plane q) + { + return -distance2 (q, p); + } + + template T distance (plane p, point q) { - auto d = dot ( - p.coefficients, - q.template redim (1) - ); - - return d / norm (normal (p)); + return distance2 (p, q) / norm (normal (p)); }