|
Math help!!! (pg. 2)
|
View this Thread in Original format
| 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 ed up values, should they be radians when getting there sine and cosine values? |
|
|
| 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 |
|
|
| Joss Weatherby |
| 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. ;) |
|
|
| Omega_M |
| 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 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? |
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 ed 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. |
|
|
| tachobg |
Are you sure you're converting the output angle back to degrees?
Check that -- if that's not what's up, then post code. |
|
|
| Joss Weatherby |
| Hey guys thanks for the help so far, I havent had a chance to test it yet, I have to write some stupid manual , but I plan to look at it ASAP. |
|
|
| Dervish |
| Just use complex numbers surely? Been aggggeees since I've done this pish though. |
|
|
| rT19 |
| dude who would come to the c0r for a math advice... |
|
|
| Dervish |
>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. |
|
|
| Zild |
| I would help you but I don't feel like it. |
|
|
|
|