Home > src > BN_pol_rec > Hsand > getDistance.m

getDistance

PURPOSE ^

Returns distance vector dist = [Near Neutral FarAway] and sum(dist) = 1;

SYNOPSIS ^

function airDist = getDistance(enemy_pos, vi)

DESCRIPTION ^

 Returns distance vector  dist = [Near Neutral FarAway] and sum(dist) = 1;
 Near and Far Away are S-functions 
 Neutral is triangular function

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002  function airDist = getDistance(enemy_pos, vi)
0003  % Returns distance vector  dist = [Near Neutral FarAway] and sum(dist) = 1;
0004  % Near and Far Away are S-functions
0005  % Neutral is triangular function
0006  
0007  airDist = [0.33 0.34 0.33];
0008  very_large_dist = 300;
0009  largeDist = 250;
0010  mediumDist = 150;
0011  smallDist = 50;
0012  dVec = [];
0013  for i = 1:length(enemy_pos)
0014   dVec = [dVec; sqrt((vi(1) - enemy_pos(i,1))^2 + (vi(2) - enemy_pos(i,2))^2)]; 
0015  end
0016 [minValue, Idx] = min(dVec);
0017 %minValue
0018 %enemy_pos
0019 
0020 if (minValue < smallDist)
0021     airDist = [1 0 0];
0022     return;
0023 end;
0024 
0025 if (minValue < mediumDist)&&(minValue >= smallDist)
0026     k = -1/(mediumDist - smallDist); 
0027     airDist(1) = 1 + (minValue - smallDist)*k;
0028     airDist(2) = 1 - airDist(1);
0029     airDist(3) = 0;
0030     return;
0031 end; 
0032 
0033 if ((minValue < largeDist)&&(minValue >= mediumDist))
0034     airDist(2) = 1 - (minValue - mediumDist) *(1/(largeDist - mediumDist));
0035     airDist(3) = 1 - airDist(2);
0036     airDist(1) = 0;
0037     airDist;
0038     return;
0039 end;
0040  
0041 if (minValue >= largeDist)
0042     airDist = [0 0 1];
0043     airDist;
0044     return;
0045 end;
0046 
0047 
0048 
0049

Generated on Wed 16-Mar-2005 09:17:47 by m2html © 2003