closest point from a a given point to a line

Правка en1, от Harolinch, 2018-09-10 14:35:30

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);
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Harolinch 2018-09-10 14:35:30 545 Initial revision (published)