将角度风向转换为文本单词
我有来自风向标的风向数据,数据以 0 到 359 度表示。
我想将其转换为具有 16 个不同方向的文本格式(罗盘)。
基本上我想知道是否有一种快速灵活的方法将角度读数缩放为 16 个字符串数组,以打印出正确的风向,而无需使用一堆 if 语句并检查角度范围
可以找到风向 此处。
谢谢!
I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.
I want to convert this into text format (compass rose) with 16 different directions.
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
Wind direction can be found here.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
编辑:
由于每 22.5 度就有一个角度变化,因此方向应在 11.25 度后交换方向。
因此:
使用 327-348 之间的值(整个 NNW 频谱)无法产生 eudoxos 答案的结果。
经过深思熟虑,我找不到他逻辑中的缺陷,所以我重写了自己的逻辑。
步骤:
EDIT :
Since there is an angle change at every 22.5 degrees, the direction should swap hands after 11.25 degrees.
Therefore:
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..
STEPS :
这是 steve-gregory 答案的 javascript 实现,它对我有用。
有关逻辑的解释,请参阅他的答案。
Here's a javascript implementation of steve-gregory's answer, which works for me.
See his answer for an explanation of the logic.
此 JavaScript 适用于只需要 8 个基本方向并想要相应箭头的任何人。
对于风,按照惯例,箭头是相反的,因为角度表示源的方向而不是运动的方向。
This JavaScript will work for anyone who only needs 8 cardinal directions and would like corresponding arrows.
For wind, the arrows are reversed by convention, as the angle indicates the direction of the source rather than movement.
注意舍入,349...11 之间的角度应为“N”,因此先添加半个扇区 (+(360/16)/2),然后按 %360 处理超过 360 的溢出,然后除以 360/16:
Watch out for rounding, angles between 349...11 should be "N", therefore add half sector first (+(360/16)/2), then handle overflow over 360 by %360, then divide by 360/16:
我检查了这个,效果很好而且看起来很准确。
资料来源: http://www.themethodology.net /2013/12/how-to-convert- Degrees-to-cardinal.html 作者:阿德里安·史蒂文斯
I checked this and it works very good and seems accurate.
Source: http://www.themethodology.net/2013/12/how-to-convert-degrees-to-cardinal.html by Adrian Stevens
我相信更容易:
I believe it is easier to:
这是一个单行 python 函数:
显然它可以分成多行以提高可读性/pep8
Here's a one-line python function:
Obviously it can be split into multiple lines for readability/pep8
如果您到达这里并且只对将您的学位分为 8 个方向之一感兴趣。
If you arrived here and are only interested in breaking your degrees into one of 8 directions.
我可能只会做简单的度数除法来获取数组中的位置或枚举值或可以为您提供所需文本的内容。将您的所有部门向下舍入。 360/16 = 22.5,因此您需要除以 22.5 以获得位置。
字符串[] a = [N,NNW,NW,WNW,...,NNE]
I would probably just do simple division of degrees to get a position in an array or an enum value or something that would give you the text you need. Just round down on all your division. 360/16 = 22.5, so you would want to divide by 22.5 to get the position.
String[] a = [N,NNW,NW,WNW,...,NNE]
这很好用
this works fine
要进行相反的转换(罗盘字母缩写为度数):
To do the reverse conversion (compass letter abbreviations to degrees):
Javascript 函数 100% 工作
步骤
希望有帮助
Javascript function 100% working
steps
Hope it helps
我大量使用 R,因此需要一个解决方案。这是我想出的方法,并且适用于我喂给它的所有可能的组合:
I use R heavily and needed a solution for this. This is what I came up with and works well for all possible combinations I have fed it:
想要使用@eudoxos,但需要将所有部分放在一起:
借用@Hristo markow来检查结果:
Wanted to use @eudoxos but needed to pull all the parts together:
Borrrowed @Hristo markow to check the results:
这是 flutter/dart 版本:
Here is a flutter/dart version:
在 Excel 中使用了这个:
VLOOKUP(MROUND(N12,22.5),N14:O29,2,FALSE)
单元格 N12 是需要答案的方向(以度为单位)。
范围 N14:O29 正在查找扇区(A 到 R):
WIND SECTOR
0A
22.5乙
45℃
67.5D
90E
112.5 华氏度
135克
157.5小时
180焦耳
202.5K
225升
247.5M
270牛
292.5P
第315章
337.5R
Used this in Excel:
VLOOKUP(MROUND(N12,22.5),N14:O29,2,FALSE)
Cell N12 is direction toward in degrees for which an answer is needed.
The range N14:O29 is looking up the sector(A to R):
WIND SECTOR
0 A
22.5 B
45 C
67.5 D
90 E
112.5 F
135 G
157.5 H
180 J
202.5 K
225 L
247.5 M
270 N
292.5 P
315 Q
337.5 R