TranceAddict Forums

TranceAddict Forums (www.tranceaddict.com/forums)
- Chill Out Room
-- Math help!!!
Pages (2): [1] 2 »


Posted by Joss Weatherby on Sep-29-2009 10:37:

Read This! Math help!!!

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 fucking 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?


Posted by boris_the_bear on Sep-29-2009 10:45:

to put it simple


Posted by basd on Sep-29-2009 10:46:

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?


Posted by Joss Weatherby on Sep-29-2009 10:50:

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.


Posted by Meat187 on Sep-29-2009 11:18:

-2.2 °


Posted by Meat187 on Sep-29-2009 11:24:

Re: Math help!!!

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


Posted by basd on Sep-29-2009 11:36:

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.


Posted by winston on Sep-29-2009 13:13:

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.


Posted by Acton on Sep-29-2009 13:15:

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


Urgh!


Posted by colonelcrisp on Sep-29-2009 14:57:

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


Posted by verndogs on Sep-29-2009 16:16:

This is why you want to go to school instead of being a bum


Posted by TranceOwnsLol on Sep-29-2009 16:27:

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();
}
}


Posted by Joss Weatherby on Sep-29-2009 16:34:

all this -5 stuff is great but where do i start making them negatives, this is an arbitrary list of values, not something i have defined.

Winston I tried that but I keep getting fucked up values, should they be radians when getting there sine and cosine values?


Posted by TranceOwnsLol on Sep-29-2009 16:42:

use constructors? this is in java.

public class AvgAngles{

int a;
int b;
int....etc;

public AvgAngles (int x, int y....etc)
{
a=x;
b=y;
)

void run()
{
System.out.println(a+b+..../5)
}

public static void main (String[] args)
{
AvgAngles calc=new AvgAngles(first value, second value) //these parameters are to be passed to the constructor
calc.run();
}
}

you can change all the ints to float or double if you want


Posted by Joss Weatherby on Sep-29-2009 16:57:

quote:
Originally posted by TranceOwnsLol
use constructors? this is in java.

public class AvgAngles{

int a;
int b;
int....etc;

public AvgAngles (int x, int y....etc)
{
a=x;
b=y;
)

void run()
{
System.out.println(a+b+..../5)
}

public static void main (String[] args)
{
AvgAngles calc=new AvgAngles(first value, second value) //these parameters are to be passed to the constructor
calc.run();
}
}

you can change all the ints to float or double if you want


Thanks, but I am not having trouble with how to do it programmatically, just that I am getting what looks like incorrect numbers when I do it.

Also, just to help you a bit, you could simplify that easy with arrays.


Posted by Omega_M on Sep-29-2009 18:57:

quote:
Originally posted by 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 fucking 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?


You should not average the sine and cosine values. Just sum all sines, sum all cosines. Calculate sum(sine)/sum(cos) and then take inverse tan of the number. Convert it back to degrees, and you will get about -2.2. Don't ignore zero. Cosine(0) = 1 !

quote:
Originally posted by Joss Weatherby
all this -5 stuff is great but where do i start making them negatives, this is an arbitrary list of values, not something i have defined.

Winston I tried that but I keep getting fucked up values, should they be radians when getting there sine and cosine values?


Because the list is arbitrary, you need to use the sine and cosine method. That takes care of the arbitrariness. And yes, they should all be in radians. By using sines and cosines you are using vectors to solve the problem.

So you represent 355 (in rad) as i*cos(355*pi/180) + j*sin(355*pi/180), where i and j are unit vectors along 2 perpendicular lines X and Y, forming a plane, where you are measuring the angles from the X axis in the counter clockwise direction. You represent all numbers in this way. Then you add up all cosines, you add up all the sines, and you end up with a vector, i*A + j*B, where A, B are the sums of the cosine and sine terms. The angle of this vector is ATAN(B/A). Multiply by 180/pi and convert it back to degrees. This is your average angle.


Posted by winston on Sep-29-2009 19:10:

galileo galilei


Posted by tachobg on Sep-29-2009 21:26:

Are you sure you're converting the output angle back to degrees?
Check that -- if that's not what's up, then post code.


Posted by bananas on Sep-29-2009 22:16:

wolframalpha?


Posted by Joss Weatherby on Sep-29-2009 23:55:

Hey guys thanks for the help so far, I havent had a chance to test it yet, I have to write some stupid manual shit, but I plan to look at it ASAP.


Posted by Dervish on Sep-29-2009 23:57:

Just use complex numbers surely? Been aggggeees since I've done this pish though.


Posted by Reza on Sep-30-2009 00:02:

dude who would come to the c0r for a math advice...


Posted by Dervish on Sep-30-2009 00:08:

>Xplians<

Think if you have them in as engineers would call j notation (as above) you can pretty much just add them. Well like real + real, imaginary + imaginary.


Posted by Zild on Sep-30-2009 00:39:

I would help you but I don't feel like it.


Posted by Joss Weatherby on Sep-30-2009 02:28:

quote:
Originally posted by rT19
dude who would come to the c0r for a math advice...



Actually lots of math smarties here, have helped me in the past.


Pages (2): [1] 2 »

Powered by: vBulletin
Copyright © 2000-2021, Jelsoft Enterprises Ltd.