NXC tan function
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
NXC tan function
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?
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC tan function
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?
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?
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC tan function
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.
It looks like that should work. I will test when the batteries are charged. Thanks for the help.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC tan function
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.
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
atan2d(), if you like degrees more than radians.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Who is online
Users browsing this forum: No registered users and 15 guests