using atan in a sketch...

Help! I am new at this. I am trying to get the atan of a Y value and a Z value.

for example if my Y value is 0.59 and my Z value is 0.87, then we have:

degrees = arctan of (0.59/0.87)
degrees = arctan (0.6782)
degrees = 34.14

So, how do I insert this into my sketch?

I tried

xdeg = atan (yValue / zValue);

This returns a number that is NOT the accurate degree measurement. BTW, xdeg was declared as
a float variable. Also yValue and zValue were declared as float.

I am get data for xdeg, but not the accurate degree result, instead, when for example Y=.59 and Z=.87, I get xdeg as 0.61...that is clearly not 34.14 degrees.

So how do I use atan to get the arctan (in degrees) of any variable?

thanks and HELP!

The answer is in radians. Google it.

a7

Nope. that is not working. my X, Y, and Z are G-forces using an accelerometer mpu5060. The math way of get the degrees is to take the G forces such as

Y = 0.59 and Z = 0.87

such as 0.59 / 0.87 = 0.6782

then I take the atan of 0.6782 and I get 34.14 degrees with is the actual angle of the mpu5060 accelerometer. So the 0.6782 is not in radians, it is the Gforce of Y / Gforce of Z.

I am sorry I did not add that earlier. Can you help me with this? What I want to do is to take the serial data output from the accelermtr and then divide Y / Z and then use atan to get the angle.

Thanks

essentially what I want to do is to take a number that is the result of Y/Z and then get the atan of that number. So how do I write that into my sketch?

atan() gives the answer in radians.

ok.. thanks...i got it working and giving results in degrees ( the goal). next I would like to generate a graphic display of the device moving and displaying the x and y..like a video in realtime of the motion of the device. I will have to study that.

4x1ks:
essentially what I want to do is to take a number that is the result of Y/Z and then get the atan of that number. So how do I write that into my sketch?

edit: sorry, too slow.

are you playing dumb or in over your head?

degrees = atan(y/z) * 57.2957795131;

if that’s not your solution, atan isn’t your problem.

HTH

a7

Yep. just slow I guess. Thanks for reminding me. I will try to think faster.