Boost logo

Geometry :

Subject: Re: [geometry] calculating the projection of a point on a line
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2016-08-03 10:19:42


Hi Jeremy,

Jeremy Murphy wrote:
> Dear Geometers,
>
> I have looked, but I cannot find an algorithm (in BG) to calculate the
> projection of a point on a line, as per the explanation here:
> http://cs.nyu.edu/~yap/classes/visual/03s/hw/h2/math.pdf
> <http://cs.nyu.edu/%7Eyap/classes/visual/03s/hw/h2/math.pdf>
>
> Have I simply missed it or is there a simple combination of algorithms
> to calculate it?
>
> So far I have been rolling my own linear algebra computation as per
> that paper, but I was hoping to simplify the code and use something
> built in.

There is no such algorithm in BG.

There are however tools allowing to do basic linear algebra computation
(using points as vectors). Actually what you'd like to do is implemented
as a part of projected_point distance strategy:

https://github.com/boostorg/geometry/blob/develop/include/boost/geometry/strategies/cartesian/distance_projected_point.hpp#L119

This strategy calculates the distance between a point and its projection
into a segment. So you could extract a part of the code from there.

You could also try to use Boost.QVM library newly added to Boost.

Regards,
Adam



Geometry list run by mateusz at loskot.net