有一般解决方案吗?
Have a distribution of a discrete number N of angular values in the interval [0:360] Map these N values onto a unit circumference. Automatically determine the two values between which all other values are.
Is there a general solution?
最满意答案
一种方法是计算平均角度,从你的所有角度减去这个,得到-circle / 2和circle / 2之间的结果(如果你使用弧度,例如圆是2pi)并取范围(意味着 - 角度+这些的最小值,平均角度+最大值)。
这可能至少在两个方面失败:你可能无法找到一个平均角度(北,东,南,西的平均值?),最小和最大可分别是-circle / 2和circle / 2,所以你的范围将是整个圈子。
我认为计算平均角度的“正确”方法是将所有角度转换为单位向量,取平均值并使用atan2求平均向量的方向; 这是平均角度。 但请注意,在n,e,s,w示例中,平均单位向量将为0,0而atan2将返回nan。
如果您使用的是C(ish)语言,则数学库函数余数对于标准化角度非常方便; 余数(a,圆)将在-circle / 2和circle / 2之间。
One way would be to compute the mean angle, subtract this from all your angles, getting a result between -circle/2 and circle/2 (where eg circle is 2pi if you are using radians) and take the range to be (mean-angle + the min of these, mean-angle + the max).
This could fail in at least two ways: you might fail to find a mean angle (whats the mean of north, east, south, west?) and the min and max could be -circle/2 and circle/2 respectively, so your range would be the whole circle.
I think the 'proper' way to compute the mean angle is to turn all the angles into unit vectors, take the average of these and use atan2 to find the orientation of the mean vector; this is the mean angle. But note that in the n,e,s,w example, the average unit vector would be 0,0 and atan2 would return nan.
If you're using a C (ish) language the math library function remainder is handy for normalising angles; remainder( a, circle) will be between -circle/2 and circle/2.
更多推荐
发布评论