having a point p1(x0, y0) and want to find the projection of p1 on the line L given in form ax + by + c = 0
let the projection point is p2(x1, y1), so how to find x1 and y1 ?
i have a code segment which do so but i don't understand it, so can someone help me to understand it ?
the code is
point closest_point (line l, point p)
{
double k = (l.a * p.x + l.b * p.y + l.c) / (l.a * l.a + l.b * l.b);
return point (p.x - l.a * k, p.y - l.b * k);
}