Advertisement

dot product and angles > 180

Started by July 01, 2002 12:58 PM
3 comments, last by Caesar 22 years, 7 months ago
hi! i''ve done my first vector class just a few secs ago and I have a question. I also added a proc to check whether a point is inside a triangle (make three vectors, from the point to the "vertices'' of the triangle, get angles between the vectors and make sum, if 360, it''s inside). I drew it on paper and placed the point outside. Then drew the three vectors and the sum is still 360 (while one of the angles is > 180). Okay, anyway, when doing the dot product, how do we distignuish whether we want the inner or the outter angle???? )) I know there''s a leak in my knowledge, so help me get rid of it, Thnx
If you use the formula

arccos(Dot(v1,v2) / (|v1|*|v2|))

then the resulting angle will always be in the range 0 to PI radians. This is usually the inner angle, but it all depends on your problem. If you want to do the point in triangle test that you have described, then the angle given by this formula should be correct, IMO.

Cédric
Advertisement
fine, thanx
You got it wrong. The dot product will never give you an angle over 180 degrees or PI/2 in radians. Try it with a calculator. Or think of the graph, each y value occurs twice in 360 degrees.


> Okay, anyway, when doing the dot product, how do we
> distignuish whether we want the inner or the outter
> angle???? ))

As other posters have noted you don''t: the dot product doesn''t give you this information. You can either

use atan2 on each vector to get the bearing of each then compare them.

use the outer/cross product. The direction of this depends on whether the rotation between the vectors is clockwise or anticlockwise (in some frame of reference), and this can be interpreted as inner vs. outer angle.
John BlackburneProgrammer, The Pitbull Syndicate

This topic is closed to new replies.

Advertisement