Angle between two vectors matlab

后端 未结 5 1672
伪装坚强ぢ
伪装坚强ぢ 2020-12-06 07:52

I want to calculate the angle between 2 vectors V = [Vx Vy Vz] and B = [Bx By Bz]. is this formula correct?

VdotB = (Vx*Bx + Vy*By         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 08:13

    The solution of Dennis Jaheruddin is excellent for 3D vectors, for higher dimensional vectors I would suggest to use:

    acos(min(max(dot(a,b)/sqrt(dot(a,a)*dot(b,b)),-1),1))
    

    This fixes numerical issues which could bring the argument of acos just above 1 or below -1. It is, however, still problematic when one of the vectors is a null-vector. This method also only requires 3*N+1 multiplications and 1 sqrt. It, however also requires 2 comparisons which the atan method does not need.

提交回复
热议问题