Negative angles?

16 views
Skip to first unread message

Marc Lefebvre

unread,
Aug 30, 2016, 12:20:27 AM8/30/16
to Glowscript Users
I'm going to be integrating physics modeling with GlowScript into my high school physics curriculum this year, and I've gotten to the part where I'm working on displacement vectors (although this would be an appropriate question for velocity vectors as well).  What I'm trying to do is print the displacement vector in a "magnitude @ angle" format under the canvas or graph.

I'm doing this by getting the displacement vector (dm) in the loop with "dm=ball.pos-ball_start".  I'll perform a "mag" operation on this to get the magnitude.

To get the angle, I'm creating a generic x-axis vector in my setup with "xv=vec(30,0,0) and then I'm getting the difference between the displacement vector and this generic x-vector with "ang=diff_angle(dm,xv).

So, the print line looks like "print(mag(dm),"@",ang).  I'm getting angles, but none of them are going negative.  I can see the angle pass through zero, but there's no indication that the angle is going below the x-axis.

Is my approach flawed (most likely as I have little programming experience :) ), or am I bumping up against a limitation of the operation?

Thanks for any help or suggestions
Marc

Bruce Sherwood

unread,
Aug 30, 2016, 12:38:11 AM8/30/16
to Glowscript Users
The diff_angle function is obtained by taking the arccosine of the dot product of two unit vectors. This is the only definition that makes sense in 3D -- there's no such thing as a "negative" angle in 3D. The following will do what I think you want (in 2D):

a = vec(-1,1,0)
print(degrees(atan2(a.y,a.x)))

Marc Lefebvre

unread,
Aug 30, 2016, 8:52:59 PM8/30/16
to Glowscript Users
Makes sense, and your suggestion worked perfectly!  Thank you so much.

Marc
Reply all
Reply to author
Forward
0 new messages