How this calculation works
Measure the symmetric Hausdorff distance between complete planar line segments, including their interiors. The result supplies lower and upper bounds in each direction and point-to-segment witnesses for the observed discrepancy.
h(A,B)=sup_(a∈A) inf_(b∈B)||a−b||; H(A,B)=max(h(A,B),h(B,A)).A worked example
Two segments from(0,0)to(2,0) and from(0,1)to(2,1) remain exactly one unit apart. Each directed Hausdorff distance is1, so their symmetric distance is1. Refinement narrows the computed upper bound to within the entered tolerance.
Good to know
2–50 points per planar polyline,finite coordinates within±1000000. Absolute gap tolerance0.0001–0.1. Lipschitz midpoint subdivision capped at50000 steps per direction. Reject repeated consecutive vertices when detected;no vertex-only or discrete-Frechet substitution.
Treat the polylines as sets of continuous segments
A polyline represents every point on its consecutive segments, not just its entered vertices. For each point on the first polyline, the directed Hausdorff quantity asks how close the nearest point on the second polyline can be.
The directed quantity then takes the largest of those nearest distances. Reversing the roles can change the answer, so the symmetric Hausdorff distance is the larger of the two directed results rather than their sum or average.
Compare this with the Discrete Frechet distance calculator for two ordered polylines. Frechet distance respects traversal order;Hausdorff measures geometric set proximity.
Order affects segment geometry but not traversal coupling
Consecutive coordinate rows determine which points are connected by straight segments. Changing their order can therefore change the geometric set, even though merely reversing an otherwise identical path preserves that set.
Unlike Frechet distance, Hausdorff distance does not require matching points to move monotonically along both paths. Use a shared Cartesian unit and a suitable projection before comparing geographic coordinates, since this implementation uses ordinary Euclidean distance.
Nearest points lie on segments, not only endpoints
For a query point and one target segment, orthogonal projection gives the closest point on its supporting line. Clamping the projection parameter to the segment interval selects either that interior foot or a nearest endpoint.
Taking the minimum over all target segments gives an exact numerical point-to-polyline distance. The remaining maximization along a source segment is handled with subdivision, which avoids pretending that testing only source vertices proves the continuous maximum.
The parallel default has equal directed distances
Every point(x,0) with0≤x≤2 is one unit from its counterpart(x,1). That counterpart lies on the second segment, and no other point of the second segment can reduce the vertical separation.
The same reasoning works in reverse, proving both directed distances equal one. The default therefore checks not only a nearest-point formula but also the rule for combining the two directions into the symmetric distance.
A Lipschitz bound controls unresolved interiors
Distance to a fixed nonempty set is1-Lipschitz. Over a source subsegment, the midpoint distance plus half the subsegment length bounds all its distances from above, while evaluated points provide a feasible lower bound.
The algorithm subdivides the source subsegment with the largest remaining upper bound. It stops when the global directed upper-minus-lower gap is at most the requested tolerance, retaining a witness source point and its nearest target point.
Use bounds instead of overstating exactness
The lower value is a distance observed at an evaluated source point. The upper value includes all unresolved subsegment interiors through the Lipschitz argument. Their difference states the remaining absolute geometric resolution in the coordinate unit.
Floating arithmetic still contributes roundoff, and a subdivision cap returns an error instead of an unsupported completed bound. Repeated points and extreme scales can create numerical issues; the page is not an exact rational geometry proof for arbitrary data.
Choose the metric that matches the discrepancy
Hausdorff distance is useful when each path is a geometric trace and traversal order is irrelevant. A small value means each trace lies close to the other, but says nothing about speed, timing or matched progression along them.
For trajectory timing or monotone traversal correspondence, inspect Frechet-style models instead. For total deviation, a mean or integrated distance can answer another question. A single large protrusion can dominate Hausdorff distance even when most of both traces nearly coincide.
A few questions, answered
Are segment interiors included?
Yes. The bounds cover complete segments rather than only the input vertices.
Why report two directed values?
One trace can lie near the other while the other has an extra distant portion.
Is this discrete Frechet distance?
No. There is no monotone traversal matching between the two paths.
What does the tolerance measure?
It is the maximum absolute upper-minus-lower distance gap in the coordinate unit.