Game Development Community

Angle Between Vectors

by Jeremy Alessi · in Technical Issues · 08/06/2005 (10:51 pm) · 3 replies

I found this thread:

http://www.garagegames.com/mg/forums/result.thread.php?qt=20919

Which posts a good function. I have two issues though.

Isn't the angle between vectors:

Cos Angle = DotProduct(u, v) / Length(u) * Length(v)

I might be missing something in my trusty calculus book here but that's what it looks like. Everyone though is just using something like this:

F32 angle = mRadToDeg(mAcos(mDot(target, front)));

I can see why you need to convert from Degrees to Radians, why you're using the Arc Cosine, and why you're using the Dot Product. However, where's the divide by the product of the lengths?

What am I failing to realize here?

Additionally, where would be a good place for this function? Someone created a script version but wouldn't it be better to add this into the engine? Does anyone include a math.cs file in their projects?

#1
08/07/2005 (8:27 am)
No one???
#2
08/07/2005 (8:39 am)
They are normalized vectors.
#3
08/07/2005 (3:45 pm)
Oh, yeah that would do it! Thanks ;)