arctan takes two parameters?

Questions about GP commands and how to do things

Moderator: MSandro

Post Reply
bromagosa
Posts: 33
Joined: Sep 15th, '15, 07:11

arctan takes two parameters?

Post by bromagosa » Oct 2nd, '15, 09:46

We've noticed the arctan block takes two parameters, is that a bug?

Also, we seem to be missing the arcsin and arcos primitives.

Thanks! :)

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: arctan takes two parameters?

Post by JohnM » Oct 5th, '15, 14:32

The two-parameter form of arctan takes the length of the opposite and adjacent sides of a right triangle (i.e. dy and dx) and returns the angle. For example, "arctan 1 10" is about 5.7 degrees, "arctan 10 1" is about 84.3 degrees, and "arctan 10 0" is 90 degrees. (Note: when both parameters are zero -- i.e. all three points of the triangle are at the same position -- the angle could be anything. GP arbitrarily chooses to return zero degrees for this case.)

You can get the equivalent of the normal arctan function by putting the value you want the arctan of into the first argument slot and 1 into the second slot.

The two-parameter form of arctan has several advantages:
  • it avoids the problem of dividing by zero when dx is zero
  • it works around the entire circle, not just the first quadrant
  • it has a nice geometric explanation: for any change of position, arctan computes the direction of motion from the change in y and change in x
However, your question has made me aware of two problems with GP's current arctan block. First, the inputs are unlabeled; they should be labeled something like "dy" and "dx". (One might argue that the order should be "dx" and "dy" to be consistent with other GP blocks. What do you think?) The second problem is that GP's directions currently increase clockwise, whereas "arctan" assumes that angles increase counterclockwise. We've had discussions in the GP team about which way angles should increase. One argument is that most users would expect "increase rotation by 30" to turn the object clockwise, as they do in Logo. In contrast, trigonometry textbooks show angles as increasing counter-clockwise. So, we should either change GP's convention about direction or change arctan so that they are consistent with each other.

You can compute arcsin and arccos using arctan. Do you think arcsin and arccos are useful enough to include blocks for them? What are the applications you have in mind?

bromagosa
Posts: 33
Joined: Sep 15th, '15, 07:11

Re: arctan takes two parameters?

Post by bromagosa » Oct 6th, '15, 09:33

I see! I understand now.

My coworker is playing with some simple engine simulations and is using lots of trigonometry for those, that's why he felt he needed these primitives. I'll forward this info to him, thanks!

doloop
Posts: 3
Joined: May 24th, '17, 02:32

Re: arctan takes two parameters?

Post by doloop » May 24th, '17, 14:40

JohnM wrote: The second problem is that GP's directions currently increase clockwise, whereas "arctan" assumes that angles increase counterclockwise. We've had discussions in the GP team about which way angles should increase. One argument is that most users would expect "increase rotation by 30" to turn the object clockwise, as they do in Logo. In contrast, trigonometry textbooks show angles as increasing counter-clockwise. So, we should either change GP's convention about direction or change arctan so that they are consistent with each other.
Why not add an optional parameter that determines the direction of rotation?

Post Reply