Skip to main content
GameDev.net gamedev.net
🔒 Locked

Angle Between Some Vectors

Started by Reverse_Gecko Jul 26, 2002 at 8:20 PM 8 replies 300+ views
Original Post
Reverse_Gecko
Reverse_Gecko
Okay. I have the xyz coords of three points ABC that make a triangle, and point Z on the same plane. I need to find the angle between vector za vector zb, and between vector va and vc. The angles need to be from 0 to 360.
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
RapidStunna
RapidStunna
This is directly from Mathematics for 3D Game Programmers and Computer Graphics:



Theorem 1.4. Given two n-dimensional vectors P and Q, the dot product P . Q satisfies the equation

P . Q = ||P|| * ||Q|| * cos(a)



It should be pretty easy to solve for a. just a bit of easy math. Anyways, remember, a is in radians, not degrees. You have to convert it to degrees using *180/pi

---
My Site
Come join us on IRC in #directxdev @ irc.afternet.org
Zipster
Zipster
And just to extend on that formula:


P . Q = P.x*Q.x + P.y*Q.y + P.z*Q.z = ||P|| * ||Q|| * cos(a)


It''s nice to have that equation if you want to explore the mechanics of the dot product and why it works and how; i.e the mathamatics behind it.
Reverse_Gecko
Reverse_Gecko
i know what the dot product is, but I dont know if the dot product will return an angle over 180. like of the angle is 350 then it would return 10 instead of 350.
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
Dean Harding
Dean Harding
Using the dot product with give you the cosine of the angle, so just plug it into acos(), which will return a number between 0 and 2pi, it''s just a matter or re-scaling that value to your [-180, 180] range.


codeka.com - Just click it.
Vaporisator
Vaporisator
quote:
Original post by Reverse_Gecko
i know what the dot product is, but I dont know if the dot product will return an angle over 180. like of the angle is 350 then it would return 10 instead of 350.


If at all, it would return -10, so it''s just a matter of checking the sign...


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
python_regious
python_regious
The angle will ALWAYS be between 0 and pi radians. It will not be negative, or above pi. Finding the angle using the dot product will find the inner angle between two vectors, which, if you think about it, is always between 0 and pi. Everybody who says you''ll get "-10" as an angle and all that, is, quite simply, wrong.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Vaporisator
Vaporisator
Ooops, definetly right! Mixed it up with something else...


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.