A farmer wants to catch a pig which is 100 meters away from him. They
start running at the same time. The pig runs straight ahead, initially perpendicular to the line farmer-pig, at
constant speed. The farmer always runs in the direction where he sees
the pig (also at constant speed).
If the ratio of the speeds is 3:1 (farmer:pig), how far would the pig have traveled till the farmer caught it?
dt = .00001
px = 0
fx = 0
fy = 100
hypot = SQR((px - fx) ^ 2 + fy * fy)
dfx = 3 * dt * (px - fx) / hypot
dfy = 3 * dt * fy / hypot
px = px + dt
fx = fx + dfx
fy = fy - dfy
t = t + dt
LOOP UNTIL fx >= px OR fy <= 0
PRINT USING "###.########"; t; px; fx; fy
The above program simulates the chase and is thereby a numerical integration of the process. It finds:
37.49999905 37.49999905 37.49999341 -0.00000000
That is, the farmer and the pig meeting 37.5 meters to the right of the pig's original position, that being how far the pig traveled.
Posted by Charlie
on 2008-11-13 18:43:08