如何计算两个向量的夹角

计算两个向量的夹角

angle = atan2(vector2.y, vector2.x) - atan2(vector1.y, vector1.x);
if (angle < 0) angle += 2 * pi;

举例

vector1 = [1,1];
vector2 = [-1,-1];
angle = atan2(vector2(2), vector2(1)) - atan2(vector1(2), vector1(1));
angle*180/pi
plot([0,1],[0,1])
hold on
plot([0,1],[0,-1])
xlim([-1,1])
ylim([-1,1])

你可能感兴趣的:(Math)