[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
Today's challenge is to graphically simulate the "Pursuit Curve" path of a predator chasing a prey by sight when the prey runs in a straight line.
Background & Techniques
I recently received an interesting book titled "Chases and Escapes", (Paul
Nahin, Princeton University Press). The math gets a little heavy (i.e.
Differential Equations), but the initial approach, the "Pursuit Curve"
illustrated here, is straight forward and fun to simulate. The Dog chases the
Rabbit by always heading toward its current location. If the dog runs faster
than the rabbit (and the field is large enough), he will always achieve his
Notes for Programmers
Although we may eventually use sprites or pictures of the animals, this version uses TShape control whe we prove the concept. We dropped DogShape, RabbitShape, and HoleShape ellipses on a TPanel which defines our "playing field". It turns out that even though TPanels have a "Color" property, it is ignored, at least in D7. To get a "grassy" field, I overlaid a TImage to make a green background which must be and "sent to back" of the shapes so that they are remain visible.
When the MoveBtn is clicked, the OnClick exit sets up a loop to move the animals. RabbitCenter and DogCenter TPoint variables are derived from the RabbitShape and DogShape controls and are use to determine the line between dog and the mouse. The user set speed variables, DogSpeed and RabbitSpeed, specify the number of pixels to move in their current direction each time through the loop. The loop exits when one of three conditions is met:
.I decided to allow the Dog's starting position to be changed by the user by by dragging it to another position. This implementation is just about as simple as it gets
Also, the screenshot posted above did not originally have the animal tracks displayed butI decided that it needed them. I now display a"*" character for the dog each time it is moved in the MoveBtn. For the rabbit "track", I draw a line from its home position to the current position each time through the loop.
Suggestions for Further Explorations
Copyright © 2000-2018, Gary Darby All rights reserved.