|
getting the angle if i have the cos value |
Global Warming
Member #4,264
January 2004
|
hi, cos alfa = x x is some value that is known. what do i need to do to get that alfa angle? do i have to create some lookup table in the program and compare the value or maybe there's some easier method using some formula or sth? damn my maths ;e greets |
A J
Member #3,025
December 2002
|
libc has some cos() acos() be careful, you may need to convert from radians to degrees. ___________________________ |
Evert
Member #794
November 2000
|
arccos. |
Global Warming
Member #4,264
January 2004
|
ok so i wrote a function to return the sum of vectors. will it work? ;]
thanks ;] |
Evert
Member #794
November 2000
|
No, because you should be using atan2() te get the full 2pi angle in that case. |
Global Warming
Member #4,264
January 2004
|
Quote: Actually, if you're using vectors, you should probably store their carthesian components why should i? ;] i think it actually doesn't matter if i store x,y or angle & length. i used the second method because it seems to me that it fits better to my project ;] i modified the function so it doesn't use acos but atan. looks like it's ok now. what do you think?
|
X-G
Member #856
December 2000
|
Quote: i think it actually doesn't matter if i store x,y or angle & length Click me. Now that we're through with that... Storing Cartesian components lets you add and subtract vectors in a way that doesn't involve several slow trigonometric functions that are inaccurate to boot. That's probably the main reason why it's a horribly bad idea to represent vectors using polar coordinates. -- |
Evert
Member #794
November 2000
|
Quote: what do you think?
I still think you should use atan2, because you'll need the full 2pi range. And I still think you're probably better off storing cartesian components. |
Global Warming
Member #4,264
January 2004
|
Maybe you're right... But in my project I often need to update just the angle or the lenght of the vector. So I will need to use those 'slow trig functions', maybe not in ob_sum_of_vectors() but in: ob_vector_get_angle(), ob_vector_set_angle(), ob_vector_add_angle(), ob_vector_get_value(), ob_vector_set_value(), ob_vector_add_value() etc. EDIT: Maybe I'll just use those fixed point funtions from allegro and there will be no problem with speed? ;p
|
X-G
Member #856
December 2000
|
Floats are just as fast as fixeds on any modern CPU. And using trigonometry once or twice per tick, to get angle or magnitude, is much faster than using them hundreds of times per tick for every time you want to manipulate a vector. -- |
Global Warming
Member #4,264
January 2004
|
Hmm. But if I use fixed from Allegro which use lookup tables than it won't be a problem. After all I just wanted to know if my vector sum function will work. ;] |
X-G
Member #856
December 2000
|
Yes it will. Or are you seriously suggesting that doing 1-2 operations is as fast as doing tens or hundreds of the same operation? -- |
Global Warming
Member #4,264
January 2004
|
Yeah that's obvious that it's slower and if it'll work too slow I'll change it. But just help me correct my function because looks like it works bad and everything seems OK to me (maybe it's some other mistake in my code but please check it). EDIT: Never mind, all works fine. Thx for help. |
|