Sign in to follow this  
SelethD

how many radians in 360deg?

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
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
Ah, ok. So also your "I'm not trying to nitpick" makes more sense ;-)

To summarize: You can have a table for 0 to 45 degrees for sine and another in the same range for cosine, instead of a table for 0 to 90 degrees of sine (or else cosine). In fact that makes no difference in the amount of values, right you are. I should have emphasized in my first post to this thread that I meant one single table for both sine and cosine.

Share this post


Link to post
Share on other sites
Quote:
Original post by deavik
/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.

Yeah, that is really theoretical, since the effort of computing especially sqrt is in its order comparable to computing the sine directly. However, if not thinking about alternative solutions also better solutions will not be found.

Share this post


Link to post
Share on other sites
Does anyone know why the number of radians in a circle is 2*pi, rather than just pi? Is there a mathematical reason for it? I'd have thought having pi radians in a circle would be simpler.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bezben
Does anyone know why the number of radians in a circle is 2*pi, rather than just pi? Is there a mathematical reason for it? I'd have thought having pi radians in a circle would be simpler.

Because the circumference of a circle with radius one, the unit circle in other words, is 2*Pi. What this means is illustrated here; an arc of V radians in a unit circle is V units long.

Share this post


Link to post
Share on other sites
Perhaps it is because pi was first determined using the diameter, and not using the radius:
U := 2 * pi * r = pi * d

So it may have come to the magic pi. For the rest of the story (say the definition of radians) see the Brother Bob's post above.

[Edited by - haegarr on November 30, 2005 11:05:52 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this