Here is a simple example of how it will help you resolve a problem in FA.
The new stealth system currently tested for 3616 make you stop tracking your target under the fog of war.
In-Com proposed that, for air, it should not stop your planes from moving, but instead moving them toward the position of where your target should be if it keep the same direction and speed.
So, how can we resolve that in the code ?
First, let's pose the problem.
A is our target. At the last know position, it was going on the right at a speed of 5.
B is our plane. When A go out of sight, it was going toward A at a speed of 10.
It's a 2d vector problem. And for the sake of simplifying it, let's say that B is our reference point. He is in
X = 0, Y = 0. His speed is 10.
In this new referential, let's say that A is position is pa(-5, 10), and his velocity vector is va(5,0) (5 units on the right from B, 0 units in Y axis). This is his position at time 0 (t0).
So, at t1, his position will be pa(0,10), at t2 pa(5,10),.....
We also known that the interception point will be on a line defined by the position and velocity of A.
So first time we need to know is the minimal time needed by B to intercept A.
if vb is the speed of B, then we've got :
- Code: Select all
| pa + va * t | = t * vb
So :
- Code: Select all
(pa.x + va.x * t) ^ 2 + (pa.y + va.y * t) ^ 2 = (t * vb) ^ 2
With a little transformation :
- Code: Select all
(pa.x ^ 2 + pa.y ^ 2) + ( 2 * pa.x * va.x + 2 * pa.x * va.x) * t + (va.x^2 + va.y^2 - vb^2) * t^2 = 0
We now have a quadratic equation :
- Code: Select all
ax^2 + bx +c = 0
I guess you had to do these things a lot at school
To find x :
- Code: Select all
x = (-b +- sqrt(b^2 - 4ac)) / 2a.
And that's our interception time.
In our case :
- Code: Select all
a = (va.x^2 + va.y^2 - vb^2)
b = ( 2 * pa.x * va.x + 2 * pa.x * va.x)
c = (pa.x ^ 2 + pa.y ^ 2)
So in your example :
- Code: Select all
a = (5^2 + 0^2 - 10^2) = (25 - 100) = -75.
b = ( 2 * -5 * -5 + 2 * -5 * 0) = ( 50 + 0) = 50.
c = (-5^2 + 10^2) = 25 + 100 = 125.
upper term :
- Code: Select all
A = (-50 -+ sqrt(50^2 -4*-75*125)
A = -50 +- 200
lower term :
- Code: Select all
B = -150
So, we've got two possible interception times :
- Code: Select all
tA = (-50+200) / -150 = 1.
tB = (-50-200) / -150 = 1.666.
We keep our lower time as the one we want to use.
And, indeed, if our plane goes perpendicular ( vector vb2 = (0,10)), it will intercept A at time 1.
Eventually, it can go a little to the right and get it 0.6 seconds later.
But even we can deduct that intuitively, we need to compute the position where the plane must be going (the interception point).
That will be part 2.