[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Problem Description
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 & TechniquesI 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
goal. Notes for ProgrammersSetup: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. MovingWhen 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:
Other:.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.
Running/Exploring the Program
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |