camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
My friend recently told me about vector dot products and how you could use them to find the angle between two vectors.
Pretty useful stuff but after some thinking, I realized that I don't understand why it works at all.
So, say we've got two vectors and I do this:
radian_between now has the angle between the two vectors.
Before I knew about dot products and normalization, whenever I had to find the angle between two vectors, I would do this:
So, now that I do know about normalization and dot products..
Why does this:
Produce the same result as this:
Like, dotProduct() is really:
I don't see why "acos(x*other.x+y*other.y)" is equal to "abs(acos(x) - acos(other.x))".
I'm not sure if I'm really asking my question correctly =/
Okay..
Given two normalized vectors..
I can understand why the dot product always gives a value between -1.0 and 1.0..
What I don't get is why the dot product of the two normalized vectors will give a scalar that just so conveniently happens to give the angle between the two vectors when fed into the arc-cosine function.
Pretty useful stuff but after some thinking, I realized that I don't understand why it works at all.
So, say we've got two vectors and I do this:
Code:
Vector2D normalized_A;
Vector2D normalized_B;
//Give the two vectors some values and normalize the vectors..
float radian_between = acos(normalized_A.dotProduct(normalized_B));
Before I knew about dot products and normalization, whenever I had to find the angle between two vectors, I would do this:
Code:
Vector2D unnormalized_A;
Vector2D unnormalized_B;
//Give the two vectors some values..
float radian_A = acos(unnormalized_A.x / unnormalized_A.length());
float radian_B = acos(unnormalized_B.x / unnormalized_B.length());
float radian_between = abs(radian_A-radian_B);
So, now that I do know about normalization and dot products..
Why does this:
Code:
Vector2D normalized_A;
Vector2D normalized_B;
//Give the two vectors some values and normalize the vectors..
float radian_between = acos(normalized_A.dotProduct(normalized_B));
Produce the same result as this:
Code:
Vector2D normalized_A;
Vector2D normalized_B;
//Give the two vectors some values and normalize the vectors..
float radian_A = acos(normalized_A.x);
float radian_B = acos(normalized_B.x);
float radian_between = abs(radian_A-radian_B);
Like, dotProduct() is really:
Code:
float Vector2D::dotProduct (Vector2D const& other) {
return x*other.x + y*other.y;
}
I don't see why "acos(x*other.x+y*other.y)" is equal to "abs(acos(x) - acos(other.x))".
I'm not sure if I'm really asking my question correctly =/
Okay..
Given two normalized vectors..
I can understand why the dot product always gives a value between -1.0 and 1.0..
What I don't get is why the dot product of the two normalized vectors will give a scalar that just so conveniently happens to give the angle between the two vectors when fed into the arc-cosine function.