Suppose an ant is walking on the boundary of the square $[0,1]\times[0,1]$. I have trouble finding a formula for the shortest path from $(x_1,y_1)$ to $(x_2,y_2)$ on the square. Is there a straightforward solution? What if the ant is walking on the boundary of the cube $[0,1]\times[0,1]\times[0,1]$?
Update: I have an idea. I should define a function for the distance from the origin. Well it's obviously $x+y$, but the distance between two points is not necessarily the difference of the distances from the origin. However, if we define the clockwise distance from the origin, then subtraction of the distances from the origin would mean something, although it doesn't always work.