Jump to content
  • Advertisement
Sign in to follow this  

Calculating an angle from vectors

This topic is 4442 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

The dot product of two vectors is the cosine of the angle between them times the magnitudes of the vectors. So, if you have two vectors A <x, y> and B <z, w> with an angle T between them, then:

dot(A, B) = cos(T)*mag(A)*mag(B)


T = arccos(dot(A,B)/(mag(A)*mag(B))

dot(A,B) = x*z + y*w
mag(A) = sqrt(x*x + y*y)
mag(B) = sqrt(z*z + w*w)

Share this post

Link to post
Share on other sites
I might not entirely understand what you're asking for. If I don't, then I apologize.

To find the angle between two vectors A and B, use the geometric formula for the dot product:

A dot B = |A| * |B| * cos(alpha)

where alpha is the angle in question. With some manipulations, we have:

cos(alpha) = (A dot B) / (|A| * |B|)
alpha = cos-1((A dot B) / (|A| * |B|))

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!