• Advertisement
Sign in to follow this  

Vector to Radian equasion?

This topic is 4321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I gotta question... I have a normalized 2D vector, and I'm trying to get a radian value for its rotational orientation. For example, let's say a vector is 0.707, -0.707 (vector points up and to the right). If I look at this on a graph, I can figure out that the radian value would be roughly 0.785. However, I don't know how to turn this into an equasion that I can use in my program. Would one of you guys help me? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Take a look at this.


Edit: Just realized they only provide a calculator for it!

With a vector you can create a right triangle off of the x axis, from there is relatively easy to calculate the angle.

Share this post


Link to post
Share on other sites
arctan(y/x) = Theta (in radians). Function will only return values from Pi/2 to -Pi/2 (90 to -90 degrees) so if your trying to measure from the positive x axis youll have to take that into consideration.

Share this post


Link to post
Share on other sites
Actually atan2 takes both the y and x values, and uses quadrant information to return an angle over -PI to PI.

The canonical way to do this is:
atan2(y,x) = φ
asin(z) = θ


Which gives you yaw (φ) and pitch (θ). Avoid the degenerate case at x = 0.

Share this post


Link to post
Share on other sites
Thanks for the replies, I really appreciate it! I just got to work what I was trying to do, and I couldn't have done it without your help. Now my laser turrets rotate slowly toward their targets instead of simply 'snapping' in that direction. Pretty cool!

Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement