vectors and direction
If I have two vectors, va and vb, and their points of origin pa and pb, how do I find out if va and vb are moving toward or away from each other ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Use the dot product, and make sure the vectors are normalised. I''ll let you figure out the rest.
Death of one is a tragedy, death of a million is just a statistic.
Death of one is a tragedy, death of a million is just a statistic.

If at first you don't succeed, redefine success.
If you are only interested in moving away from / towards, you don''t need to normalise the vectors beforehand. All you are interested in is the sign of the dot product. That''s not affected by normalising.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
The dot product is not enough. Consider this, two vectors in the opposite direction.
A and B are the same vectors in both cases, so A dot B will give the same result in both cases. Still, they are moving towards eachother in one case, and away from each other in the other case.
So, without trying it, this one may work.
Given: the origin of the two vectors, pa and pb, and the vectors from their respective origin, va and vb.
Calculate the angle aa betwen va and (pb-pa).
Calculate the angle ab betwen vb and (pa-pb).
If both aa and ab are less than 90 degrees, they are moving towards eachother.
If both aa and ab are greater than 90 degrees, they are moving away from eachother.
If one is less than and the other one greater than 90 degrees (for example, they move in the same direction but with different origin), you can look at the magnitude of the two vectors in the direction of the other origin.
Note the absoulte value of cosine in the table. Maybe the table can be reduced to not test if a1 > 90 degrees by taking the real cosine value and not the absolute value, but I couldn''t find any table that worked.
This should, if everything works the way I want, say whether two points, moving in the direction of a vector, gets closer of further away from each other after a small time unit, delta T, where T is time.
Two vectors moving towards each other.A Bo------> <------oTwo vectors moving away from each other. B A<------o o------>
A and B are the same vectors in both cases, so A dot B will give the same result in both cases. Still, they are moving towards eachother in one case, and away from each other in the other case.
So, without trying it, this one may work.
Given: the origin of the two vectors, pa and pb, and the vectors from their respective origin, va and vb.
Calculate the angle aa betwen va and (pb-pa).
Calculate the angle ab betwen vb and (pa-pb).
If both aa and ab are less than 90 degrees, they are moving towards eachother.
If both aa and ab are greater than 90 degrees, they are moving away from eachother.
If one is less than and the other one greater than 90 degrees (for example, they move in the same direction but with different origin), you can look at the magnitude of the two vectors in the direction of the other origin.
a1 > 90 degrees a1 < 90 degrees|cos(aa)| * |va| > |cos(a2)| * |vb| away towards|cos(ab)| * |va| < |cos(a2)| * |vb| towards away
Note the absoulte value of cosine in the table. Maybe the table can be reduced to not test if a1 > 90 degrees by taking the real cosine value and not the absolute value, but I couldn''t find any table that worked.
This should, if everything works the way I want, say whether two points, moving in the direction of a vector, gets closer of further away from each other after a small time unit, delta T, where T is time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement