Jump to content

Get 0-360 angle between vectors in VEX


SteveNi

Recommended Posts

Hi

So I have two vectors, one is the y vector (0,1,0) and the other is an arbitrary vector called @aim, given those two I want to find the angle between those two vectors.

Now this should be pretty straight forward, just use

acos(dot(@aim,@up))

wich gives the angle in radiants, and converted to degrees would be a value from 0 to 180, but what If I want to find when the angle is positive and when its negative (not just the difference)?

For this I found this thread on the sidefx forums: https://www.sidefx.com/forum/topic/41091/?page=1#post-184272

And this Is what I have so far (look at the screenshot).

The "problem" here is that if I set the arbitrary vector to be (0,0,-1) for example, I get a negative 90 degree angle, so I guess there is a specific direction wich the last piece of code "looks for"...

 

This all comes down to know when the angle is greater than 180, but the original angle formula, as already said goes from 0-180.

There is something wrong with my code or the bheavior is normal?

If so how can I get the angle ranging from 0 to 360 degress? (I have to know when its greater than 180)

 

Thanks

Screenshot_1.jpg

Link to comment
Share on other sites

Hey,

if you want to do this on a flat plane (2d rotation) you can use atan2 instead.

otherwise you probably want to have an up vector to compare your rotation against.

then you can take the cross products between the 2 vectors.
and after that you take the dot product between that cross product and your second vector.

then see if that checking dot is positive or negative, will tell you if the rotation was clock, or counter clockwise, compared to the up vector you used.

once you know that you should be able to convert your 0-180 to a 0-360 angle.

I hope that helps :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...