kaiyu
2020-12-07 cf42a18aba4da77141dd0ea65918444636f899e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.moral.util;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class WindUtils {
 
    /**
     *@Description: 根据方向和风速,获取UV风向
     * @return:                                                                <                                                               com.moral.entity.Device>>
     * @Author: lizijie
     * @Date: 2020/12/03
     *
     * */
    public static Map<String, Double> getWind_direction_speed(List<Map<String, Object>> list){
        //定义u:水平方向,v:竖直方向
        double u = 0;
        double v = 0;
        for (Map map:list) {
            double u1 = 0;
            double v1 = 0;
            double wind_speed = Double.parseDouble(map.get("wind_speed").toString());
            double wind_direction = Double.parseDouble(map.get("wind_direction").toString());
            if (wind_speed == 0){
                continue;//如果风速为0,结束此次循环,进入下次循环
            }
            if (wind_direction==0){
                u1 = 0;
                v1 = wind_speed*1;
            }else if (0<wind_direction&&wind_direction<90){
                u1 = wind_speed*Math.sin(wind_direction);
                v1 = wind_speed*Math.cos(wind_direction);
            }else if (wind_direction == 90){
                u1 = wind_speed*1;
                v1 = 0;
            }else if (90<wind_direction&&wind_direction<180){
                u1 = wind_speed*Math.sin(180-wind_direction);
                v1 = -1*wind_speed*Math.cos(180-wind_direction);
            }else if (wind_direction == 180){
                u1 = 0;
                v1 = wind_speed*-1;
            }else if (180<wind_direction&&wind_direction<270){
                u1 = -1*wind_speed*Math.sin(wind_direction-180);
                v1 = -1*wind_speed*Math.cos(wind_direction-180);
            }else if (wind_direction == 270){
                u1 = wind_speed*-1;
                v1 = 0;
            }else if (270<wind_direction&&wind_direction<360){
                u1 = wind_speed*Math.sin(360-wind_direction);
                v1 = -1*wind_speed*Math.cos(360-wind_direction);
            }
            u = u+u1;
            v = v+v1;
        }
        Map<String,Double> windDirectionSpeedMap = new HashMap<>();
        if (u==0&&v==0){
            windDirectionSpeedMap.put("wind_direction",0.0);
            windDirectionSpeedMap.put("wind_speed",0.0);
        }else if (u==0&&v>0){
            windDirectionSpeedMap.put("wind_direction",0.0);
            windDirectionSpeedMap.put("wind_speed",v);
        }else if (u>0&&v>0){
            windDirectionSpeedMap.put("wind_direction",Math.atan2(u,v));
            windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
        }else if (u>0&&v==0){
            windDirectionSpeedMap.put("wind_direction",90.0);
            windDirectionSpeedMap.put("wind_speed",u);
        }else if (u>0&&v<0){
            windDirectionSpeedMap.put("wind_direction",Math.atan2(-v,u)+90);
            windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
        }else if (u==0&&v<0){
            windDirectionSpeedMap.put("wind_direction",180.0);
            windDirectionSpeedMap.put("wind_speed",-v);
        }else if (u<0&&v<0){
            windDirectionSpeedMap.put("wind_direction",Math.atan2(-u,-v)+180);
            windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
        }else if (u<0&&v==0){
            windDirectionSpeedMap.put("wind_direction",270.0);
            windDirectionSpeedMap.put("wind_speed",-u);
        }else if (u<0&&v>0){
            windDirectionSpeedMap.put("wind_direction",Math.atan2(v,-u)+270);
            windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
        }
        return windDirectionSpeedMap;
    }
 
}