Skip to content

Instantly share code, notes, and snippets.

@jclosure
Last active September 25, 2016 21:13
Show Gist options
  • Select an option

  • Save jclosure/3a3e9f12e3882e1f2b48cddd85808083 to your computer and use it in GitHub Desktop.

Select an option

Save jclosure/3a3e9f12e3882e1f2b48cddd85808083 to your computer and use it in GitHub Desktop.
Convert Degrees to Radians (C++)
#include <iostream>
#include <math.h> // for sin() and cos()
void getSinCos(double degrees, double &sinOut, double &cosOut)
{
// sin() and cos() take radians, not degrees, so we need to convert
static const double pi = 3.14159265358979323846; // the value of pi
double radians = degrees * pi / 180.0;
sinOut = sin(radians);
cosOut = cos(radians);
}
int main()
{
double sin(0.0);
double cos(0.0);
// getSinCos will return the sin and cos in variables sin and cos
getSinCos(30.0, sin, cos);
std::cout << "The sin is " << sin << '\n';
std::cout << "The cos is " << cos << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment