I know that if you take the dot-product of two normalized vectors, you get the cosine of the angle between them.
But if I take the dot-product of two non-normalized vectors (or one normalized, one not), how can I interpret the resulting scalar?
Others have pointed out how you can use the sign of the dot product to broadly determine the angle between two arbitrary vectors (positive: < 90, zero: = 90, negative: > 90), but there's another useful geometric interpretation if at least one of the vectors is of length 1.
If you have one unit vector \$\hat U\$ and one arbitrary vector \$V\$, you can interpret the dot product as the length of the projection of \$V\$ onto \$\hat U\$:
Equivalently, \$(\hat U \cdot V)\$ is the length of the component of \$V\$ pointing in the direction of \$\hat U\$. ie. You can break \$V\$ into a sum of two perpendicular vectors, \$V = (\hat U \cdot V) \hat U + P\$, where \$P\$ is some vector perpendicular to \$\hat U\$.
This is helpful for rewriting a vector from one coordinate system in terms of a different basis, or for removing/reflecting the component of a vector that's parallel to a particular direction while keeping the perpendicular component intact. (eg. zeroing the component of a velocity that would take an object through a barrier, but allowing it to slide along that barrier, or rebounding it away)
I'm not aware of a convenient geometric interpretation of the dot product when both vectors are of arbitrary length (other than using the sign to categorize the angle).
sqrt
anyway. But if you have such a perfectly-aligned unit vector set aside in advance, you've effectively precomputed the sqrt
and cached the result so you don't have to re-compute it.
\$\endgroup\$
CameraDir
, so you would underestimate the diagonal distance to it by counting only the component parallel to the camera's axis and not the component perpendicular.. If you want a measure of "depth" from the camera though, like what's stored in a depth buffer, the dot product will get you that.
\$\endgroup\$
If the resulting scalar is 0; then it means the 2 vectors are perpendicular to each other (angle difference 90 degrees) . If the resulting scalar > 0; then the angle difference between them is less than 90 degrees. If the resulting scale is < 0; then the 2 vectors are facing opposite directions ( or angle difference > 90 degrees).
This can be useful in calculating backstabs for example. Or determine which quadrant one vector is relative to the other.
the dot product is equal to v1.length() * v2.length() * dot(v1.normalized(), v2.normalized())
the most you can get out of that is whether the angle is acute or not or pass to other algorithms where you can delay the normalization. But you can get the normalized from the non-normalized by dividing with sqrt(v1.lengthSquared() * v2.lengthSquared())
(saves a sqrt calculation)