New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |