 Arc cosine function not functioning as expected. what am i missing?

Howdy everyone!
does anyone know why acsos(.50); returns 1.05
hers the code:

#include <math.h>

double input = 40;
double input2 =80;

double out;

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

void loop()

{

Serial.println(input);
Serial.println(input2);
out = input / input2;
Serial.println(out);
out = acos(out);
Serial.println(out);
Serial.println();

}

ans serial output

80.00
0.50
1.05

thanks guys!

–isaac

Well, it should return 1.047197, so I guess to two decimal places, 1.05 is close enough.

(You are remembering we work in radians?)

LOL that would explain it. Is there a function in math.h that converts these values into degrees? Im trying to use this for controlling servos. thanks!

--Isaac

CodeNewton: Is there a function in math.h that converts these values into degrees?

Well it's easy enough to multiply by 57.3....

Is there a function in math.h that converts these values into degrees?

The values (that you input to acos()) are in degrees. They need to be in radians. There are 2 PI radians in 360 degrees, so a little math is all that is needed. Write your own function...

The values (that you input to acos()) are in degrees. They need to be in radians.

The output of the acos function is in radians. The input is a number from -1 to +1.

Pete

Sounds easy enough. I'll write one:) Why would I need to change the ratio passed to acos into radians? Thanks --isaac

Why would I need to change the ratio passed to acos into radians?

You don't. I was think of sin() and cos() when I wrote that rubbish.