[Math] Manhattan distance between a point and straight segment specified by its end points

geometry

is there a simple way to express the Manhattan distance between a point and a segment specified by its two endpoints? The segment is limited so it's not always possibile to use the minimum distance between a point and a straight line.
I am working in R^N, not in R^2 or R^3, so i need a more general formula.

I need this for an algorithm so the solution could use "if" conditions if a close form doesn't exist.

Thank You

Wentu

Best Answer

I'll just do $\Bbb R^2$, but the extension should be clear. Let the point be $(a,b)$ and the segment from $(c,d)$ to $(e,f)$. Parameterize the segment as $(c+t(e-c),d+t(f-d))$. The distance is a linear function of $t$, so can have no local maximum or minimum. You just need to check the endpoints and the points where it is no longer differentiable. So check $(c,d),(e,f)$ and the values of $t$ where $c+t(e-c)=a$ or $d+t(f-d)=b$