简体   繁体   English

两个风向的差异

[英]Diff of two wind directions

I want to plot graph showing difference of two wind directions (measured by two different sensors not at the same place) during the time period.我想绘制显示一段时间内两个风向差异的图表(由不在同一地点的两个不同传感器测量)。

I have both values presented as azimuth, ie north = 0, east = 90, south = 180, west = 270. I am thinking about the following requirements:我将两个值都显示为方位角,即北 = 0、东 = 90、南 = 180、西 = 270。我正在考虑以下要求:

  1. absolute value of difference should be +0.. +180 such that the smaller angle between both value is used差异的绝对值应为 +0.. +180,以便使用两个值之间的较小角度
  2. the sign of the difference should be defined by defining positive value for situation where angle between valueB and valueA is smaller in the clock direction (eg valueB=50, valueA=10 or valueB=50, valueA=350) while negative value is used if angle is smaller in counter-clock direction (eg the opposite)对于值B和值A之间的角度在时钟方向上较小的情况(例如值B = 50,值A = 10或值B = 50,值A = 350),差值的符号应通过定义正值来定义,而使用负值如果逆时钟方向的角度较小(例如相反)

I think that this requirements can also be understand so that I want to rotate reference system to make valueA get azimuth = 0 and then return the azimuth of value B on the scale -180.. +180.我认为这个要求也可以理解,所以我想旋转参考系统以使 valueA 获得方位角 = 0,然后返回值 B 在比例尺上的方位角 -180.. +180。

I have something like this:我有这样的事情:

diff = abs(valueB - valueA)
if (diff >= 180) diff = 360 - diff

if (valueA < 180) offsetA = valueA else offsetA = valueA - 360
offsetB = valueB - offsetA
if (offsetB < 0) offsetB = offsetB + 360
if (offsetB >= 360) offsetB = offsetB - 360
if (offsetB > 180) diff = (-1) * diff

Question 1: Is shorter code possible?问题 1:是否可以使用更短的代码?

Question 2: Is there a better presentation of difference between two wind directions?问题2:两个风向之间的差异有更好的表述吗? I do not see how Wind Rose (which is nice for presentation of speed + direction) could be used to present the difference between two directions during the time period.我看不出如何使用 Wind Rose(非常适合表示速度 + 方向)来表示该时间段内两个方向之间的差异。

Question 3: I will use Python or R. Are there already such function implemented in some library?问题3:我会用Python或者R,有没有库已经实现了这样的功能?

If another SE forum is more appropriate, please suggest.如果其他SE论坛更合适,请提出建议。

In a CodeProject article I wrote way back in 2011 "Circular Values Math and Statistics with C++11" I addressed the same problem.在我早在 2011 年写的一篇 CodeProject 文章“C++11 的循环值数学和统计”中,我解决了同样的问题。 I called it the directed distance between two circular values .我称它为两个圆形值之间的定向距离

If the inputs are in the range [0..360) you can use the following:如果输入在 [0..360) 范围内,您可以使用以下内容:

// the length of the directed walk from c1 to c2, with the lowest absolute-value length
// return value is in [-180, 180)
double Sdist(double c1, double c2)
{
    double d = c2 - c1;
    if (d <  -180.) return d + 180.;
    if (d >=  180.) return d - 180.;
                    return d       ;
}

I also defined another distance type for circular values: the increasing distance (clockwise).我还为圆形值定义了另一种距离类型:递增距离(顺时针)。

// the length of the increasing walk from c1 to c2 with the lowest length
// return value is in [0, 360)
double Pdist(double c1, double c2)
{
    return c2 >= c1 ? c2 - c1 : 360. - c1 + c2;
}

See sections 8 and 9 in the article.请参阅文章中的第 8 和第 9 节。 The article and source code with some fixes are also available on GitHub . GitHub 上还提供了这篇文章和带有一些修复的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM