Archived

This topic is now archived and is closed to further replies.

TheBlackJester

Converting MSVC++ from radians to degrees

Recommended Posts

TheBlackJester    142
Hey, It seems as though MSVC++ works in radians rather than degrees. I know i can get around it by using DegToRadian functions and stuff but i'll lose accuracy in my calculations that way. Is there any way to set MSVC++ to read it in degrees instead? 'Very funny, Scotty. Now beam down my clothes.' - Edited by - TheBlackJester on January 13, 2002 1:59:16 AM

Share this post


Link to post
Share on other sites
BaShildy    122
Use a preprocessor macro (#define) to convert it for you at compile time so there is no loss in performance, and you gain the readability you want.

- Kevin "BaShildy" King
Game Programmer: DigiPen
www.mpogd.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Remember, there are 2*PI radians in a circle. So 360 degrees ~= 2 * PI radians. So to convert degrees to radians, just do this:

#define DEG2RAD(deg) (PI/180 * deg)

someFunctionDegrees(DEG2RAD(360));

Hope this helps!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Using radians is more accurate than degrees since they''re expressed with floats.

Share this post


Link to post
Share on other sites
TheBlackJester    142
Thnx,

Its true that they are expressed with floats, but if my angle is some number in degrees and I then convert that to radians, I lose data because of the non-exactness of conversion. In my case i need my camera to not be moving on the X axis if a given angle is 0, but since it was converted to radians its actually 0.010221 and is causing my cam to "float". This is un acceptable

''Very funny, Scotty. Now beam down my clothes.'' -

[TheBlackJester]

Share this post


Link to post
Share on other sites
ragonastick    134
Why not just use radians everywhere and not bother about conversions anywhere? Unless you have to have the user entering angles or reading angles, then I see no reason to use degrees.

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
always use radians, never degrees. If you think you are having precision problems just use some sort of tolerance thing instead of the equality operator. If you switch back and forth you deserve the imprecision. Degrees have no value in math, science, or programming.

Share this post


Link to post
Share on other sites
Beer Hunter    712
Exactly. The formulas for all the trig functions are based on radians. If you want to use the trig functions, you should stay with radians.

I''ve seen some people who will read in an object''s position, calculate the angle from another point, convert that angle to degrees and store it. Later on, they read the angle, convert it back to radians (!!) and use it. I have to wonder what goes on inside their brains...

Alternatively, you can use lookup tables and your own angle units. Duke Nukem 3D, IIRC, had 2048 angle units in a circle.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Also, you''re asking for trouble by testing a float against 0.0f. This:
if (f <= 0.01f)

is a better bet than this:

if (f == 0.0)

Share this post


Link to post
Share on other sites