From 371131a67325c28fedf85dacec5b6b123c657ced Mon Sep 17 00:00:00 2001 From: cilix42 Date: Mon, 19 May 2008 16:01:37 +0000 Subject: [PATCH] Nearest point from point to line (simplicistic convenience function) --- src/2geom/nearest-point.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/2geom/nearest-point.h b/src/2geom/nearest-point.h index 43b76c3ab..73ac0c3ce 100644 --- a/src/2geom/nearest-point.h +++ b/src/2geom/nearest-point.h @@ -48,6 +48,17 @@ namespace Geom { +/* + * Given a line L specified by a point A and direction vector v, + * return the point on L nearest to p. Note that the returned value + * is with respect to the _normalized_ direction of v! + */ +inline double nearest_point(Point const &p, Point const &A, Point const &v) +{ + Point d(p - A); + return d[0] * v[0] + d[1] * v[1]; +} + //////////////////////////////////////////////////////////////////////////////// // D2 versions -- 2.30.2