Java 由角度得到风向,由风速得到风力

气象上把风吹来的方向确定为风的方向。因此,风来自北方叫做北风,风来自南方叫做南风。气象台站预报风时,当风向在某个方位左右摆动不能肯定时,则加以“偏”字,如偏北风。当风力很小时,则采用“风向不定”来说明。风向的测量单位,我们用方位来表示。如陆地上,一般用16个方位表示,海上多用36个方位表示;在高空则用角度表示。用角度表示风向,是把圆周分成360度。北风(N)是0度(即360度),东风(E)是90度,南风(S)是180度,西风(W)是270度,其余的风向都可以由此计算出来。 

import java.util.HashMap;
import java.util.Map;

public class WeatherSwitchUtil {
    private static Map<String, String> windPowerMap = getWindInfo();
    private static Map<String, String> windDirectMap = getWindDirect();

    public static String getWindPower(double windVelocity){
        for(Map.Entry map : windPowerMap.entrySet()){
            String windRegion = map.getValue().toString();
            String windName = map.getKey().toString();
            if(windRegion.indexOf("-") != -1){
                String[] windRegionArray = windRegion.split("-");
                double windMin = Double.parseDouble(windRegionArray[0]);
                double windMax = Double.parseDouble(windRegionArray[1]);
                if(windVelocity >= windMin && windVelocity <= windMax + 0.1){
                    return windName;
                }
            }

            if(windRegion.indexOf(">") != -1){
                double windMin = Double.parseDouble(windRegion.split(">")[0]);
                if(windVelocity >= windMin){
                    return windName;
                }
            }
        }

        return "风";
    }

    public static String getWindVelocity(double windVelocity){
        for(Map.Entry map : windDirectMap.entrySet()){
            String windRegion = map.getValue().toString();
            String windName = map.getKey().toString();
            if(windRegion.indexOf("-") != -1){
                String[] windRegionArray = windRegion.split("-");
                double windMin = Double.parseDouble(windRegionArray[0]);
                double windMax = Double.parseDouble(windRegionArray[1]);
                if(windVelocity >= windMin && windVelocity <= windMax + 0.01){
                    return windName;
                }

                if(windVelocity >= 348.76 || windVelocity <= 11.25){
                    return windName;
                }
            }
        }

        return "风";
    }

    private static Map<String, String> getWindInfo(){
        Map<String, String> windPowerMap = new HashMap<>();
        windPowerMap.put("无风", "0.0-0.2");
        windPowerMap.put("软风", "0.3-1.5");
        windPowerMap.put("轻风", "1.6-3.3");
        windPowerMap.put("微风", "3.4-5.4");
        windPowerMap.put("和风", "5.5-7.9");
        windPowerMap.put("清风", "8.0-10.7");
        windPowerMap.put("强风", "10.8-13.8");
        windPowerMap.put("劲风", "13.9-17.1");
        windPowerMap.put("大风", "17.2-20.7");
        windPowerMap.put("烈风", "20.8-24.4");
        windPowerMap.put("狂风", "24.5-28.4");
        windPowerMap.put("暴风", "28.5-32.6");
        windPowerMap.put("台风", ">32.6");
        return windPowerMap;
    }

    private static Map<String, String> getWindDirect(){
        Map<String, String> windDirectMap = new HashMap<>();
        windDirectMap.put("北", "348.76-11.25");
        windDirectMap.put("北东北", "11.26-33.75");
        windDirectMap.put("东北", "33.76-56.25");
        windDirectMap.put("东东北", "56.26-78.75");
        windDirectMap.put("东", "78.76-101.25");
        windDirectMap.put("东东南", "101.26-123.75");
        windDirectMap.put("东南", "123.76-146.25");
        windDirectMap.put("南东南", "146.26-168.75");
        windDirectMap.put("南", "168.76-191.25");
        windDirectMap.put("南西南", "191.26-213.75");
        windDirectMap.put("西南", "213.76-236.25");
        windDirectMap.put("西西南", "236.26-258.75");
        windDirectMap.put("西", "258.76-281.25");
        windDirectMap.put("西西北", "281.76-303.75");
        windDirectMap.put("西北", "303.76-326.25");
        windDirectMap.put("北西北", "326.26-348.75");
        return windDirectMap;
    }
}
private String getWindDirection(double WIN_D_Avg_2mi){
        String windDirection;
        if(WIN_D_Avg_2mi == 0 || WIN_D_Avg_2mi == 360 ){
            windDirection = "北";
        } else if(WIN_D_Avg_2mi == 90){
            windDirection = "东";
        } else if(WIN_D_Avg_2mi == 180){
            windDirection = "南";
        } else if(WIN_D_Avg_2mi == 270){
            windDirection = "西";
        } else if(WIN_D_Avg_2mi > 0 && WIN_D_Avg_2mi < 90){
            windDirection = "东北";
        } else if(WIN_D_Avg_2mi > 90 && WIN_D_Avg_2mi < 180){
            windDirection = "东南";
        } else if(WIN_D_Avg_2mi > 180 && WIN_D_Avg_2mi < 270){
            windDirection = "西南";
        } else {
            windDirection = "西北";
        }

        return windDirection;
    }

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风铃峰顶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值