问题
I am trying to determine if the movement of two objects is "in phase" or opposing each other. So basically I have two vectors, R1, R2 in R^3 and I want to know if they "point in the same direction".
I can think of two ways to compute that: a) Calculate the angle between the two vectors. The angle indicates their alignment. b) Calculate the correlation coefficient between the two vectors. (e.g. using Matlab's corr function) 1 means they are parallel, -1 antiparallel. If they are perpendicular I do get either plus or minus 0.5, which seems wrong.
Is there a difference in using the two methodologies? My gut feeling says that the two methods should be identical, but I am not sure. Anyone has some insights and what could be potential differences/advantages of the methods? Thanks!
回答1:
This is most easily done by calculating the dot product between the two normalized vectors. The inverse cosine gives directly the angle between the vectors.
Matlab doesn't have a "corr" function. It has "xcorr". The cross correlation between two 3 element vectors is a 5 element vector. The middle element of that is the same as the dot product, so it's basically the same calculation.
来源:https://stackoverflow.com/questions/28570724/correlation-between-two-vectors-vs-angle-between-vectors