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