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

## 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 on other sites
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.

atan2(y,x) ?

##### 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 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 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!

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633338
• Total Posts
3011417
• ### Who's Online (See full list)

There are no registered users currently online

×