1 function d = dist_point_line(q, p1, p2)
2 %
function d = dist_point_line(q, p1, p2)
4 %
function computing the distance of the 2d-point q from the line
5 % through the points p1, p2.
6 % If q,p1,p2 is a matrix with columnwise points, then a vector of
7 % distances is generated.
9 % Bernard Haasdonk 10.5.2007
24 if (size(p1,2)~=2) || (size(p2,2)~=2) || (size(q,2)~=2)
25 error('Only 2d points acceptable in distance computation
');
28 % d = area(triangle(q,p1,p2)*2 / dist(p1,p2))
30 % d = zeros(size(p1,2),1);
31 A = abs(area_triangle(q,p1,p2));
33 d = A * 2 .* sqrt(dp1p2(:,1).^2 + dp1p2(:,2).^2).^(-1);