Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Possible Duplicate:
How do you calculate the average 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?

like image 850
Kenny Avatar asked Mar 04 '11 03:03

Kenny


People also ask

How do you find the mean of a bearing?

Bearings of lines may be calculated if bearing of one of the lines and the included angles measured clockwise between the various lines are given. Bearing of a line = given bearing + included angle.

How do you find the average of two results?

How to Calculate Average. The average of a set of numbers is simply the sum of the numbers divided by the total number of values in the set.


2 Answers

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.

enter image description here

like image 60
Dr. belisarius Avatar answered Sep 30 '22 16:09

Dr. belisarius


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
like image 21
user168715 Avatar answered Sep 30 '22 16:09

user168715