1. Originally Posted by Geometrian
If you normalize the two vectors, (length = 1), then dot them, you'll get a right triangle. The dot product is the projection of the vectors onto each other.

So, http://mathdl.maa.org/images/upload_.../Dray2/dot.gif. Suppose your two vectors are v and w. The dot product is the base of that right triangle in the image. Notice the right triangle it forms. Because v is normalized, the length of the hypotenuse is 1, so the base of the right triangle (dot product) is the cosine of the angle theta. So, take the arccosine of the dot product, and you'll get theta.

Note that this works in any number of dimensions.
But this is the same as the formula above, except v and w are normalized, hence the denominator is 1.

2. yeah, I am using cartesian coordinate..except this one is reversed..
the baffling thing is..except I swap the values around...
I think I can continue working from now on..thanks very much Elysia..missed you on this forum

Thanks Geometrian

3. What is all this talk of a right triangle? If you have two coordinates you can form a right triangle quite easily but you do not need to for this problem.

Code:
```// Returns a scalar that is the arccosine of the angle between the vectors
// v1 and v2 must be unit vectors if the angle is needed - IE: normalized vectors
// For simple sign comparison v1 and v2 do not need to be normalized
float Dot(const Vector3 &v1,const Vector3 &v2)
{
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
}```
This is C++. Note that C# does not have const and Vector3 should be a struct or value type instead of a reference type.

If you only need the angle between two vectors you simply normalize the vectors, dot them, and take the arccosine of the result to get the angle. If you only need to test the sign of the result (actually more useful than the angle) then the vectors do not need to be normalized as this does not affect the result.

The dot product is probably the most important operation in computer graphics and is used all over the place because it's geometric meaning is extremely important and applicable to nearly every operation and test you need to perform in graphics and games.

4. That has already been mentioned, Bubba. In the first two replies, actually. And they don't require you to normalize your vectors first. I don't know if it's common/good practice to normalize vectors in computer graphics, though.

5. Originally Posted by Elysia
I don't know if it's common/good practice to normalize vectors in computer graphics, though.
It depends. Generally speaking, raw datas' parameters should be normalized (i.e., your object data should have normalized geometry). When rendering, some things can mess this up--e.g. scaling, linear or nonlinear, (although the normal matrix (transpose of the inverse model*view matrix) counters this).

However, in some cases, you will need to explicitly normalize your vectors. For example, in a fragment program, normals are linearly interpolated from the vertex program, changing their lengths. Often, the first thing one does in a fragment program is normalize such parameters (also commonly applies to tangents and binormals).

Ian