Deviation.java 701 B

1234567891011121314151617181920
  1. package com.gyee.runeconomy.service.WindDirection;
  2. public class Deviation {
  3. // 计算风速偏差率
  4. public static double calculateSpeedDeviation(double fanSpeed, double towerSpeed) {
  5. if (towerSpeed == 0) {
  6. throw new IllegalArgumentException("Tower speed cannot be zero.");
  7. }
  8. return Math.abs(towerSpeed - fanSpeed) / towerSpeed * 100;
  9. }
  10. // 计算风向差值
  11. public static double calculateDirectionDeviation(double fanDirection, double towerDirection) {
  12. double difference = Math.abs(towerDirection - fanDirection);
  13. if (difference > 180) {
  14. difference = 360 - difference;
  15. }
  16. return difference;
  17. }
  18. }