1. package body Swarm_Configuration is 
  2.  
  3.    use Real_Elementary_Functions; 
  4.  
  5.    ------------------------------ 
  6.    -- Inter_Swarm_Acceleration -- 
  7.    ------------------------------ 
  8.  
  9.    function Inter_Swarm_Attraction   (x : Distances) return Acc_Scalar is 
  10.  
  11.       Attract_Close : constant Acc_Scalar := -((Arctan ((x - Attract_Close_Centre) * Attract_Close_Steepness) / Pi) + 0.5); 
  12.       Attract_Far   : constant Acc_Scalar := +((Arctan ((x - Attract_Far_Centre)   * Attract_Far_Steepness)   / Pi) - 0.5); 
  13.  
  14.    begin 
  15.       return -Attract_Strength * Attract_Close * Attract_Far; 
  16.    end Inter_Swarm_Attraction; 
  17.  
  18.    -- 
  19.  
  20.    function Inter_Swarm_Repulsion    (x : Distances) return Acc_Scalar is 
  21.  
  22.       Repulse : constant Acc_Scalar := -((Arctan ((x - Repulse_Centre)       * Repulse_Steepness)       / Pi) - 0.5); 
  23.  
  24.    begin 
  25.       return Repulse_Strength * Repulse; 
  26.    end Inter_Swarm_Repulsion; 
  27.  
  28.    -- 
  29.  
  30.    function Inter_Swarm_Acceleration (x : Distances) return Acc_Scalar is 
  31.  
  32. --        Repulse       : constant Acc_Scalar := -((Arctan ((x - Repulse_Centre)       * Repulse_Steepness)       / Pi) - 0.5); 
  33. --        Attract_Close : constant Acc_Scalar := -((Arctan ((x - Attract_Close_Centre) * Attract_Close_Steepness) / Pi) + 0.5); 
  34. --        Attract_Far   : constant Acc_Scalar := +((Arctan ((x - Attract_Far_Centre)   * Attract_Far_Steepness)   / Pi) - 0.5); 
  35.  
  36.    begin 
  37. --        return Repulse_Strength * Repulse - Attract_Strength * Attract_Close * Attract_Far; 
  38.       return Inter_Swarm_Repulsion (x) + Inter_Swarm_Attraction (x); 
  39.    end Inter_Swarm_Acceleration; 
  40.  
  41.    -- 
  42.    -- 
  43.    -- 
  44.  
  45.    function Approach_Acceleration    (x : Distances; 
  46.                                       Velocity_Towards_Goal : Real) return Acc_Scalar is 
  47.  
  48.    begin 
  49.       return Approach_Strength * (Max_Approach_Velocity * Arctan (Approach_Steepness * x) - Velocity_Towards_Goal); 
  50.    end Approach_Acceleration; 
  51.  
  52.    -- 
  53.    -- 
  54.    -- 
  55.  
  56.    function Approach_Acceleration    (Velocity_Towards_Goal : Real) return Acc_Scalar is 
  57.  
  58.    begin 
  59.       return Approach_Strength * (Max_Approach_Velocity - Velocity_Towards_Goal); 
  60.    end Approach_Acceleration; 
  61.  
  62.    -- 
  63.    -- 
  64.    -- 
  65.  
  66.    function Velocity_Matching (Velocity, Velocity_Difference : Velocities) return Accelerations is 
  67.  
  68.       Proposed_Acceleration : constant Accelerations := (-Velocity_Matching_Strength) * Velocity_Difference; 
  69.       Small_Interval        : constant Real := 0.01; 
  70.  
  71.    begin 
  72.       if abs (Velocity + Small_Interval * Proposed_Acceleration) > abs (Velocity) then 
  73.          return Proposed_Acceleration; 
  74.       else 
  75.          return Zero_Vector_3D; 
  76.       end if; 
  77.    end Velocity_Matching; 
  78.  
  79.    -- 
  80.  
  81. end Swarm_Configuration;