Angle between two vectors in 3d

Hello,
I have two vectors in 3d and i want to find the angle between those two vectors.
Thanks in advance

 Respuesta aceptada

Jan
Jan el 20 de Sept. de 2011

7 votos

Or:
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))

9 comentarios

developer
developer el 20 de Sept. de 2011
Thanks simon :)
actually i have seen this thread before and confused with
angle = atan2(norm(cross(a,b)), dot(a,b))
and
acos(dot(v1, v2) / (norm(v1) * norm(v2)))
Jan
Jan el 20 de Sept. de 2011
The ATAN2 approach has a higher numerical stability, but it is slower. Although Matlab states in the documentation, that ACOS from the FDLIBM library is use, I cannot reproduce the results exactly using the source from netlib.org. But the differences concern the angles very near to 0 and 180 degrees.
TAEYUN
TAEYUN el 30 de Oct. de 2014
hey simon I have some questions if i have 3values of x,y,z how can i find angle between two 3d vectors?
Bineet_Mehra
Bineet_Mehra el 28 de Abr. de 2016
I have u1 v1 w1(velocity components) volumetric data. Size of u1 is NxNxN (N is 100) and same is true frol v1 and w1.
I have one more case of u2, v2, w2, each one of size NxNxN. both these data sets are obtained from TriScatteredInterp and meshgrid. Basically i plotted streamlines for these two cases and now i want to see how much deviation is there between these streamlines (from case 1 to 2.). I need to find the angle between them at the points given by meshgrid. But cross product wont work (A and B must have at least one dimension of length 3.).. any suggestion ?? Thanks a lot
Jan
Jan el 28 de Abr. de 2016
@Bineet_Mehra: Please open a new thread for a new problem. Otherwise you cannot accept an answer as a solution.
I guess you want:
vel1 = [u1(:), v1(:), w1(:)]
vel2 = [u2(:), v2(:), w2(:)]
Now the cross-product should work.
Bineet_Mehra
Bineet_Mehra el 29 de Abr. de 2016
@Jan Simon, Thanks for your suggestion. I shall open a new thread and will try the solution given by you.
Thanks
Dyuman Joshi
Dyuman Joshi el 1 de Feb. de 2023
@Jan the CSSM thread you linked does not exist anymore.
Do you happen to have an archived link for that thread?
I am unable to find the thread by simply searching the title, on the Google Groups (CSSM archive)

Iniciar sesión para comentar.

Más respuestas (3)

Lucas García
Lucas García el 20 de Sept. de 2011

3 votos

You can use the subspace function to find the angle between two subspaces:
>> subspace([1;0;0],[0;1;0])
ans =
1.5708

1 comentario

Yadu Bhusal
Yadu Bhusal el 5 de Ag. de 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?

Iniciar sesión para comentar.

David Young
David Young el 20 de Sept. de 2011

0 votos

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.

2 comentarios

developer
developer el 20 de Sept. de 2011
Thanks actually i have seen the post referred by Jan simon
and confused that what is the difference between
angle = atan2(norm(cross(a,b)), dot(a,b))
and
acos(dot(v1, v2) / (norm(v1) * norm(v2)))
Jan
Jan el 20 de Sept. de 2011
Mathematically identical, but numerically more stable, when the vectors have very different lengths:
acos(dot(v1 / norm(v1), v2 / norm(v2)))

Iniciar sesión para comentar.

rashi
rashi el 15 de Jun. de 2018

0 votos

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

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Sept. de 2011

Comentada:

el 1 de Feb. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by