Tuesday, 9 December 2014



Simulation of Real/Pure Pursuit problem



Hot PursuitWhen target is aware of the pursuer.

Pure Pursuit- When target is not aware of pursuer. In this case, the course of the target is known.

Pure Pursuit Problem example


A fighter aircraft sights an enemy bomber and flies directly toward it, in order to catch up and destroy it. We have to determine the attack the attack course of the fighter and how long does the fighter take to catch up with the bomber.

If the target flies along a straight line, the problem can be solved directly with analytic techniques. But if the path of the bomber is curved, the problem can not be solved directly. We can solve such problems using simulation.

We are given following conditions:
  1. Both target and pursuer are flying in the same 2 dimensional plane.
  2. The fighter's speed is constant that is VF.
  3. The target's path is known.
  4. Minimum distance required by the fighter to fire a missile at bomber is 10 units.
  5. If the target is not caught within given time t (here t = 12), the target escapes.
  6. Initial coordinates of the pursuer (fighter) are known.

We will choose our coordinate system such that, initially target will be lying on the X axis and pursuer will be lying on Y axis as shown in the figure below.

The fighter looks at the target at instant t, aligns its velocity vector with line of sight (i.e. points itself towards the target). It continues to fly in that direction for one unit of time (up to t+1). At (t+1) it looks at the target again and realigns itself.
The distance between the 2 (dist[t]) at a given instant of time can be calculated by using distance formula.

dist[t] = √( (yb[t]-yf[t])² + (xb[t]-yf[t])² )

The angle θ of the line from fighter to target at a given time t is given by

Sin 
θ =  (yb[t]-yf[t]) /dist[t]
Cos 
θ = (xb[t]-xf[t]) /dist[t]

Using these values, next position of fighter at time (t+1) is
xf[t+1]= xf[t] + VF 
Sin θ
yf[t+1]= yf[t] + VF
Cos 
θ

(try putting different velocities of fighter or different coordinates of bomber in the code given below)

Java code for the simulation:
package simulation;

/**
 *
 * @author avichal
 */
public class Simulation {

    
    public static void main(String[] args) {
        /*Co-ordinates of the bomber*/
        double[] xb={80,90,99,108,116,125,133,141,151,160,169,179,180};
        double[] yb={0,-2,-5,-9,-15,-18,-23,-29,-28,-25,-21,-20,-17};
        
        /*Co_ordinates of fighter to be determined*/
        double[] xf=new double[13];
        double[] yf=new double[13];
        xf[0]=0;
        yf[0]=50;
        
        double vf=20;   //speed of fighter
        boolean status=true;
        double dist;
        
        for (int t=0;t<12;t++)
        {
           dist=Math.sqrt((xb[t]-xf[t])*(xb[t]-xf[t])+(yb[t]-yf[t])*(yb[t]-yf[t]));
           if(dist<=10)
           {
                status=false;
                
                for(int i=0;i<13;i++)
                {
                    System.out.println(xf[i]+" "+yf[i]);
                }
                System.out.println("Target Destroyed at time t="+t);
                
                break;
           }
           yf[t+1]=yf[t]+vf*((yb[t]-yf[t])/dist);
           xf[t+1]=xf[t]+vf*((xb[t]-xf[t])/dist);
        }
        
        if(status)
        {
            for(int i=0;i<13;i++)
            {
                System.out.println(xf[i]+" "+yf[i]);
            }
            System.out.println("Target escaped!");
        }
    }
    
}