# Get rotation angle from vector

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

## Recommended Posts

I feel pretty stupid as a maths graduate, but I'm having one of those moments when you just get confused by the simplest things... From a 2D vector I want to get a rotation angle. The positive x-axis is 0. The answer should be in the range [0,2PI] - the full circle must be covered not just 1/4 or 1/2. I think the positive y-axis will be PI/2, but maybe it's -PI/2 - again this is not a problem since it's just convention which way is which. So, can someone give a simple function for this declaration:
float GetAngleFromVector(Vector2D &vec);
Technically you should normalise vec - I don't care but maybe this would be a useful thing for others but me; it's not THAT trivial is it?

##### Share on other sites
angle = atan2(vec.y, vec.x);

No normalization required; defined for all but the (near) zero vector. The angle is returned in the range [-pi,pi], but you can easily adjust that if desired. pi/2 will be along the +y axis.

##### Share on other sites
DOH!!!

Thanks a lot though, I'm not afraid to admit such a simple thing confused me and you saved me some time.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633716
• Total Posts
3013500
×