return to tranceaddict TranceAddict Forums Archive > Main Forums > Chill Out Room

Pages: [1] 2 3 
Math help!!!
View this Thread in Original format
Joss Weatherby
I need to get the average of a set of angles...


angles = [355, 358, 0, 5, 351];

So I basically convert those numbers into radians.

Then I go through the radians and I convert them to their sine and cosine values and add those up.

I then get the average (totalSine/5) and (totalCosine/5)...

I then use atan2 to convert the averages back into an angle...

It doesn't work. :( I have mixed and matched values all over the place...

I get weird ass ing numbers, like I give it two or three of the same number and I get back like 6.124125 or some really odd number.

I looked at this post: http://www.bio.net/bionet/mm/molmod...ary/000853.html

and...

this one I started off with and got those numbers to test: http://positivelyglorious.com/softw...es-of-azimuths/


Any ideas?
boris_the_bear
to put it simple
basd
It's been a while since I did geometry, so could you explain why

(355 + 358 + 0 + 5 + 351) / 5 wouldn't work?

The average of a 30 degree and a 60 degree angle is 45, isn't it?
Joss Weatherby
quote:
Originally posted by basd
It's been a while since I did geometry, so could you explain why

(355 + 358 + 0 + 5 + 351) / 5 wouldn't work?

The average of a 30 degree and a 60 degree angle is 45, isn't it?


Think about a compass, you have to account for the fact that as value goes 0 is closer to 358 than 355.
Meat187
-2.2 °
Meat187
quote:
Originally posted by Joss Weatherby
Then I go through the radians and I convert them to their sine and cosine values and add those up.


Also, I think it can be done easier than that, but you're doing it wrong right here.
tan = sin/cos
basd
quote:
Originally posted by Joss Weatherby
Think about a compass, you have to account for the fact that as value goes 0 is closer to 358 than 355.

You're right.

Then it's -2,2 indeed.

If you count 355 as -5, 358 as -2 and 351 as -9 you get

-5 + -2 + 0 + 5 + -9 = -11

-11 / 5 = -2,2. No need for any complicated geometric calculations, I suppose.
winston
i think he's looking for a way to do this on c/c++

something like

x = y = 0
foreach angle {
x += cos(angle)
y += sin(angle)
}
average_angle = atan2(y, x)


just a guess.
Acton
quote:
Originally posted by winston
i think he's looking for a way to do this on c/c++


Urgh!
colonelcrisp
just create unit vectors for each of your angles and sum them.....

verndogs
This is why you want to go to school instead of being a bum :p
TranceOwnsLol
do it in java

public class AvgAngles {

void print()

{
System.out.println(-5+-2+0+5-9/11);
}
public static void main(String[] args) {

AvgAngles calc=new AvgAngles();
calc.print();
}
}
CLICK TO RETURN TO TOP OF PAGE
Pages: [1] 2 3 
Privacy Statement