Page 1 of 1
NXC tan function
Posted: 18 Feb 2011, 11:33
by mattallen37
I just downloaded the HT NXT-G Tan block, and it allows for two inputs (x,y), but the NXC function only has parameter for one? How do I use the equal of the HT block, but in NXC?
Re: NXC tan function
Posted: 18 Feb 2011, 12:13
by ricardocrl
I don't know what that NXT-G block is about but if it takes two parameters, x and y, then it should be an arc-tangent function (called "tan-1" or "atan") and not a tan().
When you have a line and you know x and y, and you want to know tha angle, you can use: angle = tan-1(y/x). So, the NXT-G block may get the x and y as parameters and calculate the angle as result. if you want the same in NXC, use the function atan2d(y, x). That returns the angle in degrees. If you want it in radians, use just atan2(y, x).
Is these what you meant to do?
Re: NXC tan function
Posted: 18 Feb 2011, 13:06
by mattallen37
Sorry, yes it is atan2, not tan.
It looks like that should work. I will test when the batteries are charged. Thanks for the help.
Re: NXC tan function
Posted: 18 Feb 2011, 13:40
by ricardocrl
Good, you're welcome!
But you can also use atan(), with one single parameter. In that case you have to provide the result y/x as the parameter. The bad thing about this function is that y/x can be the same for 2 different angles. if you change the signal of both x and y, you will get the same angle in the atan() function. That's why the return value is between -pi/2 and pi/2. When using atan2() it gives the exact angle, ranging from -pi to pi.
Re: NXC tan function
Posted: 18 Feb 2011, 17:52
by muntoo
atan2d(), if you like degrees more than radians.