Find vector closest to X_AXIS
-
With a given set of various vectors, how do you determine which one is the one most parallel to another, say the
X_AXIS
? -
take the dot product of each vector, normalized, with the vector you are comparing against, normalized.
how_close = vector_a.normalize().dot( comparison_axis ) how_close_b = vector_b.normalize().dot( comparison_axis )
the normalize is important because they all need to be the same length for this kind of comparison.
-
Does the direction of the vector matter then?
-
Oops sorry. Meant to tack that on.
dot product = 1 means parallel and in the same direction
dot product = -1 means parallel and in the opposite direction.So if direction matters, look for closest to 1. If it doesn't, use the absolute value.
-
Great! Thank you very much!
Advertisement