# minimize distance

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)

-
You could set the partials wrt $x$ and $y$ to be zero. Alternately, draw a light ray from one point reflecting off both axes to reach the second point... – Macavity Jun 27 '14 at 5:52
@Macavity can you kindly explain the your method – user157920 Jun 27 '14 at 5:54
His method is in every physics book on optics, "How to find the image of an object in a mirror. Try it for one mirror to get comfortable with the method, then use two, each one on one coordinate axis – Lord_Gestalter Jun 27 '14 at 5:57
Can you provide a link which can be useful for this problem – user157920 Jun 27 '14 at 6:07
Let me see if I can draw something that helps you. Otherwise, search for Fermat's principle and Reflection (e.g. hyperphysics.phy-astr.gsu.edu/HBASE/phyopt/Fermat.html) – Macavity Jun 27 '14 at 6:43

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)?
@user157920 Yes. In general, you will find $H'$ and $K'$ are in II and III quadrants (or vice versa). Now any path between $H$ and $K$ which touches both axes in the manner described, has a corresponding path connecting $H'$ and $K'$ of the same length. So the straight line $H'K'$ is the shortest path, and has length $\sqrt{(h_1+k_1)^2+(h_2+k_2)^2}$. When the path passes through the origin, this is the same as the expression you put down. – Macavity Jun 27 '14 at 10:05