SelethD 456 Report post Posted November 28, 2005 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 0 Share this post Link to post Share on other sites
Illco 928 Report post Posted November 28, 2005 2 Pi radians.Radians to degrees:360 * (angle / (2Pi))Degrees to radians:2Pi * (angle / 360)Illco 0 Share this post Link to post Share on other sites
SelethD 456 Report post Posted November 28, 2005 loli knew it wouldnt be just a simple number :)so something along the lines of 2(3.14) or 6.28? 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted November 28, 2005 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] 0 Share this post Link to post Share on other sites
SelethD 456 Report post Posted November 28, 2005 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 :) 0 Share this post Link to post Share on other sites
Guest Anonymous Poster Report post Posted November 28, 2005 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) 0 Share this post Link to post Share on other sites
Drew_Benton 1861 Report post Posted November 28, 2005 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". 0 Share this post Link to post Share on other sites
deavik 570 Report post Posted November 29, 2005 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. 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted November 30, 2005 Quote:Original post by deavikremember 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 deavikPlease 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? 0 Share this post Link to post Share on other sites
deavik 570 Report post Posted November 30, 2005 Quote:Original post by haegarrHmm? 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 cos^{2}(x) = 1 - sin^{2}(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. 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted November 30, 2005 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. 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted November 30, 2005 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 cos^{2}(x) = 1 - sin^{2}(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. 0 Share this post Link to post Share on other sites
Bezben 202 Report post Posted November 30, 2005 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. 0 Share this post Link to post Share on other sites
Brother Bob 10344 Report post Posted November 30, 2005 Quote:Original post by BezbenDoes 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. 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted November 30, 2005 Perhaps it is because pi was first determined using the diameter, and not using the radius:U := 2 * pi * r = pi * dSo 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] 0 Share this post Link to post Share on other sites