将风向角度转换为文字 [英] Converting wind direction in angles to text words

查看:239
本文介绍了将风向角度转换为文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自风向标的风向数据,该数据以0到359度表示.

I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.

我想将其转换为具有16个不同方向的文本格式(玫瑰).

I want to convert this into text format (compass rose) with 16 different directions.

基本上我想知道是否有一种快速的方法来将角度读数缩放到16字符串数组以打印出正确的风向,而无需使用一堆if语句和检查角度范围

Basically I want to know if there is a fast slick way to scale the angle reading to a 16 string array to print out the correct wind direction without using a bunch of if statements and checking for ranges of angles

可以在此处找到风向.

谢谢!

推荐答案

由于角度每22.5度发生变化,因此方向应在11.25度后交换手.

Since there is an angle change at every 22.5 degrees, the direction should swap hands after 11.25 degrees.

因此:

349-360//0-11 = N
12-33 = NNE
34-56 = NE

使用327-348(整个NNW频谱)中的值无法产生eudoxos答案的结果. 经过深思熟虑,我找不到他逻辑上的缺陷,所以我改写了我自己的..

Using values from 327-348 (The entire NNW spectrum) failed to produce a result for eudoxos' answer. After giving it some thought I could not find the flaw in his logic, so i rewrote my own..

def degToCompass(num):
    val=int((num/22.5)+.5)
    arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
    print arr[(val % 16)]

>>> degToCompass(0)
N
>>> degToCompass(180)
S
>>> degToCompass(720)
N
>>> degToCompass(11)
N
>>> 12
12
>>> degToCompass(12)
NNE
>>> degToCompass(33)
NNE
>>> degToCompass(34)
NE

STEPS:

  1. 将角度除以22.5,因为360deg/16方向= 22.5deg/方向变化.
  2. 添加.5,以便在截断该值时可以打破更改阈值之间的联系".
  3. 使用整数除法截断值(因此不进行舍入).
  4. 直接索引数组并打印值(mod 16).

这篇关于将风向角度转换为文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆