开发者

How to find the average of a set of bearings [duplicate]

开发者 https://www.devze.com 2023-02-14 22:14 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do you calculate the a开发者_如何学Cverage of a set of angles?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How do you calculate the a开发者_如何学Cverage of a set of angles?

If I have a set of bearings, ranging from 1-360, how can I find the average? Usually to find the average one would add them all up and divide by the number of items. The problem here is that doing that in the case of [1, 359], 2 bearings, would result in in 180, which in fact should be 360. Any ideas?


Represent the angles as vectors with Norm=1 and average the sum.

x1 = {cos(a),sin(a)}

x2 = {cos(b),sin(b)} 

(x1+x2)/2 = {(cos(a)+cos(b))/2,(sin(a)+sin(b))/2} 

which means the angle for the mean is

atan2((sin(a)+sin(b)) /(cos(a)+cos(b)))  

Just beware of controlling the possible overflow when the denominator is close to zero.

How to find the average of a set of bearings [duplicate]


It isn't clear from your question what you're trying to define the "average" to be... for directions on a circle there is no clear-cut obvious notion of average.

One interpretation is the value x that is the closest fit to the set of provided values, in the least-squares sense, where the distance between two bearings is defined as the smallest angle between them. Here is code to compute this average:

In[2]:= CircDist[a_, b_] := 180 - Mod[180 + a - b, 360]

In[6]:= Average[bearings_] := 
 x /. NMinimize[
    Sum[CircDist[x, bearings[[i]]]^2, {i, 1, Length[bearings]}], 
    x][[2]]

In[10]:= Average[{1, 359}]

Out[10]= -3.61294*10^-15


So what you want is the middle of two bearings - what happens if you have {90, 270}? Is the desired answer 0 or 180? This is something to consider.. also what's the middle of three bearings?

One thing you could do is:

  • Take the first two bearings in your set
  • Work out the difference between the two in either direction (i.e. [1, 359] would give 2 degrees in one direction, and 358 in the other)
  • If you want the desired angle to be the middle of the acutest of the two, take that as your difference and add to the anti-clockwise most of the pair (i.e. 359)
  • Use this as the new bearing and the next (i.e. 3rd in set) as the other bearing, and repeat, until all are 'middled'.

Off the top of my head, I don't think this is going to be fair, it'll probably bias it in one direction though (i.e. maybe in preference of the later values in your set).

0

精彩评论

暂无评论...
验证码 换一张
取 消