# 27 analysis/bugs.p

Four bugs are placed at the corners of a square. Each bug walks always
directly toward the next bug in the clockwise direction. How far do
the bugs walk before they meet?

analysis/bugs.s

Since the bugs start out walking perpendicularly, and there is nothing
in the problem to alter this symmetry, the bugs are always walking
perpendicularly. Since each bug is walking perpendicularly to the line
separating it from the bug chasing it, the gap is closing at the speed
of the chasing bug. Therefore, each bug walks a distance equal to the
side of the square before it meets the next bug.

In order to conveniently express the equation of the bugs' motion,
use standard polar coordinates, and let the first bug's position at
any instant be (r(t), theta(t)). Assume the initial square is
centered at the origin.

Then by symmetry the bugs are always at four corners of some square
centered at the origin, and if they meet they meet at the origin.
Also, each bug is always walking in a direction pi/4 (45 degrees) away
from the radial line to the origin. This means that in the limit as
the time step goes to zero, the bug travels sec(pi/4) = sqrt(2) units
along its path for every unit of progress made good toward the center.
Since the corners are initially d/sqrt(2) distance from the center,
each bug travels distance d before they meet, assuming they meet at
all.

Since a bug's path always crosses radial lines at angle psi = pi/4,
the path is a logarithmic spiral with angle psi = pi/4 and equation

r(t) = e^(a*theta(t) + b)

Moreover since the bugs walk clockwise, both r(t) and theta(t)
decrease as t increases, in other words r increases as theta
increases, hence a is positive. Also, psi = pi/4 gives us

d(r)/d(theta) = r

(this is easiest to see by drawing the path for a small time step
delta-t and taking the limit as delta-t goes to 0). The solution is

r(t) = e^(theta(t) + b)

(that is, a = 1). As we know, this spiral makes infinitely many
"wraps" around the origin as the radius approaches zero, but it does
have finite length from any point inward and its limit point is the
origin, where the bugs will meet (unless one wants to quibble about
the behavior at the exact limit point).

How much closer is the bug to the origin after its first complete cycle
around the origin? Recall that r(0) = d/sqrt(2). As the bug walks
clockwise around the origin, after one full circuit its angle decreases
from theta(0) to theta(t1), where t1 (the time at which full circuit
occurs) is defined by

theta(t1) = theta(0) - 2*pi

Hence

```  r(0) = e^(theta(0) + b)
r(t1) = e^(theta(0) - 2*pi + b)

r(t1)/r(0) = e^(-2*pi)
```

The quantity we want is

```  r(0) - r(t1) = r(0)*(1 - e^(-2*pi))
= d * (1 - e^(-2*pi))/sqrt(2)
```

Continue to: