Built in functions (std, etc.) for converting Degrees to Radians?

Nov 30, 2014 at 8:45pm
Hello,

I have a simple question that I didn't find an answer to while googling.

Are there STD functions for converting degrees to radians and radians to degrees?

I know I can write my own but in the particular application I would like to use built-in ones for maintainability.

Thank you for your time.
Nov 30, 2014 at 10:58pm
No, there is none.
In future, you can use reference to know about standard library content:

http://www.cplusplus.com/reference/ 
http://en.cppreference.com/w/
Dec 1, 2014 at 2:35am
I'll usually just have a constant variable called "toRadians" = Pi / 180.0 and another called "toDegrees" = 180.0 / Pi. Wouldn't even need a function call.
Then you can easily do cos(45*toRadians);
Last edited on Dec 1, 2014 at 2:37am
Dec 1, 2014 at 5:40am
¿where did you get `Pi'?

I can only visualize a small set of angles, and those I already know their sin or cos, so I hate when applications ask me for degrees, that they will convert to radians, and compute their sin and cos to make a rotation.
Dec 1, 2014 at 4:19pm
Thanks everyone!

@ne555 the values are "defines" in Math.h
Dec 1, 2014 at 4:25pm
tmason wrote:
@ne555 the values are "defines" in Math.h
Pi is not defined in math.h/cmath header. Some implementations might define it, but it is non-standard and unsupported/
Dec 1, 2014 at 4:30pm
I stand corrected; any include file where it is defined as standard or is it best to define it yourself in your own includes?
Dec 1, 2014 at 4:34pm
Yeah I would just define it yourself.

¿where did you get `Pi'? ...so I hate when applications ask me for degrees
Yeah I just defined it myself, didn't mean to cause confusion.
The first thing that comes to my mind is an art program like photoshop or paint, much easier to ask the user for a degree than radian. I'm sure some programs let you specify if the user wants to use radians or degrees, of course.
Last edited on Dec 1, 2014 at 4:44pm
Dec 1, 2014 at 4:38pm
1) If you already using Boost, you can get Pi as boost::math::constants::pi<double>();
2) If you do not use boost, it is often better to define it yourself:
1
2
3
const double Pi = 3.14159265358979323846264; //constant expression
const double Pi = std::atan2(0, -1); //Calculated in runtime
const double Pi = std::acos(-1); 
Last edited on Dec 1, 2014 at 4:40pm
Dec 1, 2014 at 10:08pm
> an art program like photoshop or paint, much easier to ask the user for a degree than radian.
¿In what operation? I can't seem to picture a case where I would want a box to write 42 degrees.
Would rather move a point, slide a bar, or pick an already done slope.
And in technical drawing, those weird angle measures would be calculated from other dimensions.

And for well know angles, 1/6, 1/4, 1/3 (pi implicit) are a lot more clear than 30, 45, 60.
Topic archived. No new replies allowed.