Reputation: 23
I found the following page: https://glm.g-truc.net/0.9.4/api/a00131.html
And I am having issues with understanding why the following two are equivalent...
The following code:
glm::vec3 vec = vector1 - vector2;
distance = glm::length(vec);
Is equivalent to:
distance = glm::distance(vector1, vector2);
How is it that the length of the vector resulting in subtracting two vectors is equivalent to the distance between the vectors?
Upvotes: 1
Views: 5275
Reputation: 141
This diagram might help understand what is happening here: we have two vectors, a and b, which correspond to your vector1 and vector2. The difference vector of those two reaches from b to a. Its length equals exactly the distance between the two coordinates that describe a and b. If you switch a and b around, the difference vector simply changes direction.
Upvotes: 4