Jump to content
  • Advertisement
Sign in to follow this  
SelethD

how many radians in 360deg?

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am generating a lookup table for rotation, and i need to loop through all 360 degrees, but i need to do this in radians, so how many radians == 360 degrees? Thanks

Share this post


Link to post
Share on other sites
Advertisement
2 Pi radians.

Radians to degrees:
360 * (angle / (2Pi))

Degrees to radians:
2Pi * (angle / 360)

Illco

Share this post


Link to post
Share on other sites
Nothing is simple ;-)

I assume the look-up table contains some trigonometric values in dependence of the angle? If so, then there is no real need to not have 360 values in the table, e.g. this way:
table[angle_in_deg] = sin(angle_in_deg/(2*PI));

Say: It's the question for _what_ you need radians: For the index or else for the value at the index (however, also in the former case you could do a radian to degree conversion before indexing, of course).

(BTW: You may also take into account that sin(x) = cos(0.5*PI-x), and that sine and cosine are periodic, so that w/ a little bit of case distinction a look-up for 90 degrees could be sufficient.)

EDIT: Bug in sin - cos relation correct; thx to deavik's hint below.

[Edited by - haegarr on November 30, 2005 4:29:15 AM]

Share this post


Link to post
Share on other sites
ok, i see. by using a lookup table i dont really need radians, just the formula for init my table, which you have provided.

Thanks :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you are going to use trig tables, do yourself a favor and use 256 "degrees" in a circle (or some other power of 2) instead of 360. This allows for very simple and extremely efficient wrapping of angles using a bitwise and operation.

- Rockoon (Joseph Koss)

Share this post


Link to post
Share on other sites
Slightly O/T but, do a google search for "how many radians in X degrees", where X is the number of degrees you are looking for, and it will calculate it for you. Google Calculator is definitly one of those resources you should keep handy! Just throwing that out for anyone who has not seen that cool functionality [wink]. You can even do things such as "6.28318531 radians / pi".

Share this post


Link to post
Share on other sites
Quote:
Original post by haegarr
(BTW: You may also take into account that sin(x) = cos(x-0.5*PI) ...

Just to save SelethD any confusion he may later have--you should remember that as sin(x) = cos(π/2 - x), and not the other way round. Since cos(-x) = cos(x), it does not make any difference in this case; but it will if you try to use the related relation cos(x) = sin(π/2 - x) in the form cos(x) = sin(x - π/2)--you will get an incorrect result.

Please note haegarr, I'm not trying to nitpick [smile]--the rest of the post was very good, including the idea for 90 degree lookups. As a matter of fact--because you can use the above mentioned relation, a 45 degree lookup will do.

Share this post


Link to post
Share on other sites
Quote:
Original post by deavik
remember that as sin(x) = cos(π/2 - x), and not the other way round.

Thx for the hint. Have corrected the arg's sign in my post above.

Quote:
Original post by deavik
Please note haegarr, I'm not trying to nitpick [smile]--the rest of the post was very good, including the idea for 90 degree lookups. As a matter of fact--because you can use the above mentioned relation, a 45 degree lookup will do.

Hmm? The reduction formulas of sin and cos functions are for angles between 90 and 360 degrees. At 90 degrees the sine curve has reached the first maximum. How should this be reduced to 45 degrees (pi/2 is 90 degrees). Am I missing something?

Share this post


Link to post
Share on other sites
Quote:
Original post by haegarr
Hmm? The reduction formulas of sin and cos functions are for angles between 90 and 360 degrees. At 90 degrees the sine curve has reached the first maximum. How should this be reduced to 45 degrees (pi/2 is 90 degrees). Am I missing something?

After I re-read my post, I think you misunderstood that a little. It will be enough to have values corresponding to the range 0->45 degrees for both sin(x) and cos(x). If you want to keep just the values of sin(x) in your table, then you will need values for 0->90 degrees.

Boils down to the same thing, though ... because sin (x) = cos (90 - x).

/edit: Theoretically, it's possible to drive a lookup using just the values of sin(0) through sin(45) and using the relation cos2(x) = 1 - sin2(x) to get the values of cos 0 to cos 45. After that use the complementary angle relation and get values of sin and cos for all x 0->90. From there, it's simple. But this approach requires more computing power, using a square and a square root, and the little more memory for the lookup table (0->90) is more practical.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!