Archived

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

ISO way: radians -> degrees

This topic is 5503 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'm not sure what you mean with ISO way, but this might help you?

degree = radian * 180 / pi
radian = degree / 180 * pi

This means that 360 degrees (full circle) = 2pi, 180 degrees = pi, etc.

I'm not sure if this is what you asked for. Oh well I'll put it in a function too:

float DegreeToRadian(float degrees)
{
float radians = degrees / 180.0f * pi;

return radians;
}

float RadianToDegree(float radians)
{
float degrees = radians * 180.0f / pi;

return degrees;
}

Oh and by the way:
float pi = 3.14159

It has much more decimals, but this is quite accurate already (and I can't think of the rest right now )

---------------------------
Edit: Had to change pi from 1.14159 to 3.14159
---------------------------

[edited by - Subotron on November 21, 2002 11:51:49 AM]

Share this post


Link to post
Share on other sites
Not that I know of... it is not difficult to create your own function that can do this though.

We know that 180 degrees is equal to pi, so simply do this


#define PI 3.141592654

int radianstodegrees( float radians ){
return radians * 180/PI;
}


That oughta do it, I think I got the equation right too It has been a while since I have used it.

Oh, since the equation is so simple you may also want to __inline it so that you do not waste an extra cycle or two on calling the function.

[edited by - kurifu on November 21, 2002 11:55:02 AM]

Share this post


Link to post
Share on other sites
thanks, but i was just wondering if there was any func doing the conversion, which belongs to the ANSI/ISO C++ standard.

btw pi =(almost) 3.1415926535897932384626433832795028841971693993
learned by heart :-D

Share this post


Link to post
Share on other sites
quote:
Original post by Enselic
thanks, but i was just wondering if there was any func doing the conversion, which belongs to the ANSI/ISO C++ standard.

btw pi =(almost) 3.1415926535897932384626433832795028841971693993
learned by heart :-D


Show off.

Share this post


Link to post
Share on other sites
Although you''re not even close

http://www.netrunner.nu/~rogers/Pi_1000000.html

or why not go for the 10 million version while you''re at it

http://www.thealmightyguru.com/TheGuru/Pointless/PI/PI-10000000.zip

:D

/Sandman

Share this post


Link to post
Share on other sites
Wouldn't it be useful to be able to define quantities in their correct units. Then you wouldn't have to remember 'this is degrees' or 'this is metres', everthing would just be 'angle' or 'length' and then when you really needed to convert it to the corrects units you multiply by some appropriate factor.

I spent an evening sitting scribbling down ideas for using templates and SI units etc. Then before going ahead and reinventing the wheel I searched the web and found something to make things easier

I think there are plans to do something similar in boost in future

edit : the link in the article is out of date - here's the correct location

[edited by - petewood on November 21, 2002 12:22:36 PM]

Share this post


Link to post
Share on other sites