Tuesday, July 14, 2015

Shortest path - around the circumference or rectilinear path through

I was out running and I was faced with this approximate situation:

I was wondering whether it was shorter to run the straight rectilinear path represented by the green arrows (segments labelled with lengths r, d, and h), or shorter to run around the circumference (blue arrows).  I figured it would depend on d.  As a starting point, if d equals r, then the straight path is shorter.  Conversely, if d=0, then h = r, the rectilinear path distance is 2*r and the curved path is r * pi / 2 which is approximately 1.5 * r, and thus the curve is shorter than the rectilinear path.

For the general case of any d (between 0 and r), the length of the rectilinear path is:
p = r + d + h

We can calculate h using the pythagorean theorem:
h^2 + d^2 = r^2
h = sqrt(r^2 - d^2)

Therefore the length of the rectilinear path is:
p = r + d + sqrt(r^2 - d^2)

The length of the curved path is given by the arc length which is:
s = theta * r

Define the angle phi as being between segment d and the radius, then:
phi = acos(d / r)

Theta is 180 degrees (pi radiians) minus phi:
theta = pi - acos(d / r)

Then, the arc length is:
s = r * (pi - acos(d / r))

In theory I could set p = s and try to solve for d (or try to solve for the ratio between d and r), but I doubted I would get very far so instead I set r = 1, and then plotted both s and p as a function of d from 0 to 1.

The blue curve is the results for the circumference s and it has the expected behavior - at d=0, it is pi/2, and d=1 it is pi.  The red curve is the rectilinear path length p, it also has the expected behavior, at d=0 and d=1 it is 2, with a maximum in between.

The curves cross at approximately d=0.75, indicating that the paths are equal length when d=0.75.  If d < 0.75, the curve around the circumference is shorter; if d > 0.75 the rectilinear path is shorter.

Another way of thinking about this is how far across the diameter the rectilinear path goes when the it is equal to the curve - in that case it is (1 + 0.75) / 2 = 0.875; in other words you have to go 87.5% of the way across the diameter before you begin to do better using the rectilinear path.

This result is somewhat surprising to me; prior to doing the math I would have expected d of much less to be the break even point.  This rough rule of thumb is useful correction to that misconception.

Some future questions to be answered:
• What happens if the rectilinear path uses a chord instead of the diameter?
• What happens if it is an ellipse instead of a circle?