Angle Between Some Vectors

Started by
8 comments, last by Reverse_Gecko 21 years, 8 months ago
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
Advertisement
Look here http://freespace.virgin.net/hugo.elias/routines/r_dot.htm
The math you need is called "Dot Product"


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!!!
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
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.
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
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.
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!!!
but of course it would be in radians, not degrees. Radians are the mathematically natural way to represent angle. Degrees were invented to make division simple.
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.
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!!!

This topic is closed to new replies.

Advertisement