Determining the Angle Btwn Vectors
DiablodeMorte
Posts: 238
I have a quick question that I was unable to solve using the Search function....
If I have two coordinates(pt A and pt on an XY(cartesian) plane. I know the angle of pt A and would like to determine the angle that pt A has to be at inorder for it to be "Facing" pt B. In video game authoring this would be called VEC_TO_ANGLE. I have googled it and with my limited knowledge of advanced math I have not found a clear method.
Does anybody have any suggestions?
-DiablodeMorte
If I have two coordinates(pt A and pt on an XY(cartesian) plane. I know the angle of pt A and would like to determine the angle that pt A has to be at inorder for it to be "Facing" pt B. In video game authoring this would be called VEC_TO_ANGLE. I have googled it and with my limited knowledge of advanced math I have not found a clear method.
Does anybody have any suggestions?
-DiablodeMorte
Comments
Couldn't you use the formula " y = mx + b " in a way that compares 'm' between your two vectors
without actually needing to find the angle?
something like ...
m = ( y - b ) / x
I would think that if ptA is facing ptB then 'm' would be the same for both points. The exception
would be that if ptA or ptB were to face the other at 180 Deg out of phase. A secondary check
should be able to eliminate this scenario.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Angle = Arctan( (By - Ay) / (Bx - Ax) )
or
Angle = Arctan( (Yb - Ya) / (Xb - Xa) )
P.S. MikeK.. When I red your response I was so confused.. What the heck are the b's and a's and then I smacked my head against the table and got up and got a coke. To early to think
P.S.S. Schwabe.. I'm not entirly sure how you envision your idea.. How do I determine B? Do I use be as the Y intercept of the slope?
when the Arctan function is not available.
DiablodeMorte,
"b" is simply an offset value of "x" from the origin.
See this for reference:
mathforum.org/cgraph/cslope/mxplusb.html
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/30/2005 3:49:08 PM GMT
The dot product is
It just so happens that
so Θ = arccos((a1b1+a2b2)/ab) where ab is the product of the lengths of the vectors, ai and bi are the component value of the vector in the ith axis (x and y).
Here's a picture of the terms used:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 12/30/2005 5:53:04 PM GMT
(axbx+ayby)/sqrt((ax2+ay2)(bx2+by2)).
The benefit of the the equation is the y axis crossing (b) of a vector isn't needed, you only need the component values of the vectors. If you only have two vectors which you are comparing and the two vectors have a constant magnitude·you can simply do··(axbx+ayby) to calculate an unscaled measure of angle between the two vectors.
An alternative to the entire approach is to switch the coordinate system you use to store your vectors into magnitude and angle, then you can just subtract the angle component of your vectors to determine the angle between the two.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10