๐Ÿ“ฃ๐Ÿ“ช ๐Ÿšš Adafruit will not be shipping USPS orders Monday January 20, 2020 ๐Ÿ—“. Expedited USPS orders placed after 11am ET ๐Ÿ•š Friday January 17 will go out Tuesday January 21 ๐Ÿ“ฃ๐Ÿ“ช๐Ÿšš
0

using ATAN..HELP..I am new at this
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

using ATAN..HELP..I am new at this

by 4x1ks on Fri Sep 06, 2019 5:58 am

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!

4x1ks
 
Posts: 3
Joined: Fri Sep 06, 2019 5:57 am

Re: using ATAN..HELP..I am new at this

by adafruit_support_bill on Fri Sep 06, 2019 6:34 am

All of the C++ trigonometric functions operate in radians: https://www.arduino.cc/en/Reference/MathHeader

To convert radians to degrees, multiply by 180 and divide by pi.

adafruit_support_bill
 
Posts: 75691
Joined: Sat Feb 07, 2009 10:11 am

Re: using ATAN..HELP..I am new at this

by 4x1ks on Fri Sep 06, 2019 6:51 am

actually, my question is simpler than that now that I think about it. What I want to do is to take a number (e.g. .689) which is the result of dividing a variable Y by a variable Z, and then take the atan of that number.... for example:

I get data from my program and I could have a pair of numbers such as Y = 0.59 and Z = 0.87

So all I want to write into my sketch is:

Result = atan (Y / Z)

I need to know how to write that. When I just take the numbers and do them on my HP calculator I always get the correct answer. When I try to use the atan function in my sketch I always get errors. thanks.

4x1ks
 
Posts: 3
Joined: Fri Sep 06, 2019 5:57 am

Re: using ATAN..HELP..I am new at this

by 4x1ks on Fri Sep 06, 2019 7:56 am

ok...it is working. I am getting precise degree measurements now. thanks

4x1ks
 
Posts: 3
Joined: Fri Sep 06, 2019 5:57 am

Re: using ATAN..HELP..I am new at this

by adafruit_support_bill on Fri Sep 06, 2019 9:13 am

Good to hear. Thanks for the update.

adafruit_support_bill
 
Posts: 75691
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.