Converting SIN/ COSINE From Radians to Degrees

Hello all, first time posting and new to Arduino.

Im asking my Uno to find the Sin and Cosine of a degrees but it is giving me my answers in Radians.

This is inside an If statement in my Loop:

variable = cos (degree);

When i do the math on my calculator, i have the option to change my Cosine from (Rad) to (Deg) and the answer my Uno is giving me is in (Rad).

How do I declare it to do degree?

How do I declare it to do degree?

You can't - but you can use arithmetic to convert.
2pi radians = 360 degrees.

So I think I did that when I converted the radians Im getting from the Adafruit compass im using:

float variable = (atan2(event.magnetic.y,event.magnetic.x) * 180) / PI;

This gave me my compass heading in degrees.

Now im looking to find the Sin and Cosine of that compass heading in degrees not radians...

Possible???

I would likely accept that all trigonometric identities in the arduino programming environment work with radians. As such when computing anything, just leave them as radians. Then only convert to degrees when you absolutely need to, like printing it out for example.

In that case you could just have a conversion function that doesn't alter the original variable passed to it.
Serial.print(convert(variable));

Thank you for your response.

So no Arduino boards are able to give me the Deg Cosine/ Sin of a number?

Anyone know of another platform like Arduino that might have these capabilities?

No, but then the conversion is so trivial, I can't see why you're getting so worked up about it.

Sorry its just that the end result that Im trying to achieve requires me to have a Degree Sin/ Cosine.

Unless is there a way i use Radian Sin Cosine then convert to degrees or would that go back to the original equation you gave me AWOL?

I just wasnt sure if it changed now that Sin Cosine is involved?

I apologize Im new to all of this...

Even the simple Prime BASIC I first programmed in thirty forty (brain fart) years ago used radians.
Apart from programmable calculators (and even they use radians internally), I've never programmed anything that didn't use radians for trig.
I'm sorry, maybe I've become used to it, but I really don't see a problem.

const float pi = 3.14159267;

float degrees(float radians) {
  return radians / 2 / pi * 360;
}
float radians(float degrees) {
  return degrees / 360 * 2 * pi;
}

void setup() {
 Serial.begin(9600);

 Serial.print("45 degrees is ");
 Serial.print(radians(45));
 Serial.println(" radians.");

 Serial.print("1 radian is ");
 Serial.print(degrees(1));
 Serial.println(" degrees.");
}

void loop() {
}

The equation he gave you is the linear relationship between radians and degrees. You can use it to convert between the two at a whim.

2 * pi(rad) = 360(deg)

pi(rad) = 360(deg) / 2

pi(rad) = 180(deg)

A(deg) = B(rad) * (180/pi)

or

B(rad) = A(deg) * (pi/180)

It is trivial to ever use degrees in programming because everything uses radians. You just put it out of your mind and let the calculator/computer do it's thing. If you ever need degrees, you convert when needed.

So you get your variable that is filled with your radian value and use the sin function on it.
value = sin(variable);

If you ever used arcsin to return an angle in radians and needed it printed in degrees then you convert.

If he gets one in degrees, I want one in gradians.

Thank you very much for the help. I will be sticking with Radians and making it work.

Appreciate all the help guys