View Single Post
  #9  
Old August 17th, 2007, 05:04 PM
AngleWyrm's Avatar

AngleWyrm AngleWyrm is offline
Second Lieutenant
 
Join Date: Mar 2005
Location: Seattle, WA
Posts: 417
Thanks: 0
Thanked 0 Times in 0 Posts
AngleWyrm is on a distinguished road
Default Re: OT: Looking for a good physics site

Quote:
narf poit chez BOOM said:
I'm trying to code intercept calculations for two spaceships, both capable of velocity, acceleration and different positions.
The problem is in framing the question. So let me ask you about what you are trying to achieve: Does a dog chase a cat by predicting where the cat will be next frame? Does a Cheetah hunt a deer by moving towards a calculated destination? The answer of course is no.

What we are trying to implement here can be described by fighter pilots: The three modes of persuit are Pure Persuit, Lag Persuit, and Lead Persuit. Pure Persuit is probably most familiar. It involves pointing your nose directly at the target. Heat seaker missiles follow this course. Unfortunately, so do a lot of weak AI opponants. It is also fairly easy to outmaneuver; just turn so that the enemy is sleightly behind you and you will arc around him.Lag Persuit is what a dog does to a person. He points his nose behind the target, and this changes the way his target is facing fastest. It brings him around to the rear of his opponant.Lead Persuit is what is what is meant by an "intercept course", and involves pointing your nose in front of your opponant. It's what children playing a game of tag do.

On to an intercept algorithm. Instead of percieving the universe as a set of coordinates from "above", consider a 'ground-level' view. What you can do is turn to place him at any angle from you. You could turn to put him in your 12:00--dead ahead. What you can watch is what angle he is presenting to you. If you are in his 6:00 he is running straight away from you.

Let's start by saying you are both the same speed. We'll add speed difference in a moment. If he is facing directly at you, or directly away from you, then you should turn to face directly at him. What if he is facing so that you are in his 9:00 or 3:00 -- directly abreast of his run? Then you will have to run in the same direction on a parallel course until something changes. Do that by turning to put him in your 3:00/9:00.

So now we have straight-on, and parallel-course; 0~90 degrees, based on his presentation of 0~90 degrees. these are the two extremes, and the only thing left is to figure out what the middle values should be. It's easy enough for dumb animals, so we should be able to 'get it'. As the target turns more and more away from dead-on, so should you. Atan2 of his angle gives the fraction.

Now about that speed difference. If you are moving twice as fast as the target, then cut the angle change in half. Pretty cool, huh?
Reply With Quote