consider a two dimensional system. two points are given whose co-ordinates are $(h1,h2)$ and $(k1,k2)$. I want to minimize the distance between these two points with the condition that person has to go to each co-ordinates axes while going from $(h1,h2)$ to $(k1,k2)$. So possible conditions are
1.$(h1,h2)$ to $(0,0)$ to $(k1,k2)$
2.$(h1,h2)$ to $(0,y)$ to $(x,0)$ to $(k1,k2)$
3.$(h1,h2)$ to $(x,0)$ to $(0,y)$ to $(k1,k2)$
so I want to minimize this distance.
so let $(x,0)$ and $(0,y)$ be the two general points on co-ordinate axes the the distance s is given by
$s$=$s1$+$s2$+$s3$
where $s1$=$sqrt((h1)^2+(h2-y)^2)$
$s2$=$sqrt(x^2+y^2)$
$s3$=$sqrt((k1-x)^2+(k2^2))$
I could have took $x$ with $h1$ and $y$ with $k2$ but that depends upon the $(h1,h2)$ $(k1,k2)$, in either case final result will not change.
I know to minimize $s$ we need to differentiate $s$ and put it equal to 0. But since there are two variables x and y, I am not able to solve . Can someone help me with this.
thanks
some test cases
$h1$----$h$2-----$k1$------ $k2$--------$ans$--------------- $path$
1-------1---------2---------2----------- 4.242641-------(1,1)->(0,0)->(2,2)
2-------1---------1---------2------------4.242641-------(2,1)->(1,0)->(0,1)->(1,2)
1-------1---------1---------3------------4.472136-------(1,1)->(0.5,0)->(0,1)->(1,3)
Hint:
Note you could have also reflected $H$ across $x$-axis instead and $K$ across the $y$-axis. But then you may get negative intercepts for $X, Y$. Can you think through why this would give the shortest path and what happens in other cases (e.g. $H'K'$ passing through the origin)?
Alternate approach is the calculus one, or using triangle inequality (the same graph gives you the hint for that as well).