Angle between two vectors in 3d

602 views (last 30 days)
developer on 20 Sep 2011
Commented: Yadu Bhusal on 5 Aug 2021
I have two vectors in 3d and i want to find the angle between those two vectors.
Thanks in advance

Accepted Answer

Jan on 20 Sep 2011
angle = atan2(norm(cross(a,b)), dot(a,b))
See this compact discussion about this topic: CSSM: Angle between two vectors . Only 71 replies (Google finds 89 replies, so I assume 18 spam messages?) and 68300 views currently...
[EDITED]: W. Kahan suggested in his paper "Mindeless.pdf":
2 * atan(norm(x*norm(y) - norm(x)*y) / norm(x * norm(y) + norm(x) * y))

Sign in to comment.

More Answers (3)

Lucas García
Lucas García on 20 Sep 2011
You can use the subspace function to find the angle between two subspaces:
>> subspace([1;0;0],[0;1;0])
ans =
  1 Comment
Yadu Bhusal
Yadu Bhusal on 5 Aug 2021
I have 3 points in a line( suppose) and one calculations point separately. A(1,1,1)B(2,2,2)C(3 3 3) in a line and P( 5 5 5) as separate. I want to calculate angle A which is subtended by distance AP. And similar for BP,CP. Is it possible to find angles or make program to calculate these angles at once?

Sign in to comment.

David Young
David Young on 20 Sep 2011
acos(dot(v1, v2) / (norm(v1) * norm(v2)))
EDIT: Having seen Jan Simon's reply, and the long thread at CSSM that he refers to, I realise that the formula I proposed is not a particularly good one. The two methods in Jan's reply are both likely to be preferable.
Jan on 20 Sep 2011
Mathematically identical, but numerically more stable, when the vectors have very different lengths:
acos(dot(v1 / norm(v1), v2 / norm(v2)))

Sign in to comment.

rashi on 15 Jun 2018
hi I want to find the angle in azimuth and elevation plane between wo vectors in 3d. please help

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!