| 
 | 
 
 
- #include <vector>
 
 - #include <cmath>
 
  
- float calculateMostFrequentYawAngle(float Rx, float Ry, const std::vector<std::pair<float, float>>& monsterPositions, float angleRange = 25.0f)
 
 - {
 
 -     std::map<float, int> yawCounts;
 
  
-     for (const auto& pos : monsterPositions)
 
 -     {
 
 -         float dx = pos.first - Rx;
 
 -         float dy = pos.second - Ry;
 
 -         float yaw = std::atan2(dy, dx) * 180.0f / M_PI;
 
  
-         while (yaw < 0.0f)
 
 -             yaw += 360.0f;
 
 -         while (yaw >= 360.0f)
 
 -             yaw -= 360.0f;
 
  
-         for (float yawInRange = yaw - angleRange; yawInRange <= yaw + angleRange; yawInRange++)
 
 -         {
 
 -             if (yawInRange < 0.0f)
 
 -                 yawInRange += 360.0f;
 
 -             else if (yawInRange >= 360.0f)
 
 -                 yawInRange -= 360.0f;
 
  
-             yawCounts[yawInRange]++;
 
 -         }
 
 -     }
 
  
-     float mostFrequentYaw = 0.0f;
 
 -     int maxCount = 0;
 
 -     for (const auto& entry : yawCounts)
 
 -     {
 
 -         if (entry.second > maxCount)
 
 -         {
 
 -             mostFrequentYaw = entry.first;
 
 -             maxCount = entry.second;
 
 -         }
 
 -     }
 
  
-     return mostFrequentYaw;
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |