3.28 dist2d – Point-to-segment distance¶
The dist2d routine computes the shortest Euclidean distance from a point \(P\) with coordinates (xp,yp) to the segment with endpoints (x(1),y(1)) and (x(2),y(2)). If the orthogonal projection of \(P\) onto the supporting line lies within the segment, the routine returns the perpendicular distance to that line; otherwise, it returns the distance to the nearest endpoint.
Fortran:
call dist2d(d,x,y,xp,yp)
C:
dist2d(&d,x,y,&xp,&yp);
Python:
d = voft.dist2d(x,y,xp,yp)
Arguments:
|
|
|
scalar representing the shortest Euclidean distance from point \(P\) to the segment |
|
|
|
arrays of length \(2\) storing the coordinates of the segment vertices |
|
|
|
scalars storing the coordinates of point \(P\) |
Note: The segment endpoints must be distinct. The returned distance is non-negative and does not depend on the ordering of the endpoints. The routine does not explicitly handle zero-length segments.