Angles of a 3D vector

  • Thread starter susantha
  • Start date
  • #1
susantha
6
0
Hi,
Can anybody help me to find the polar angle and the azimuthal angle of a given 3D vector? Say we know the ordinates of the two point A(x1,y1,z1) and B(x2,y2,z2). So the question is find angles (Theta and Phi) of the vector AB. Any suggestion would be really appreciated.

Thanks.
Susantha
 

Answers and Replies

  • #2
tiny-tim
Science Advisor
Homework Helper
25,836
255
welcome to pf!

hi susantha! welcome to pf! :smile:

(have a theta: θ and a phi: φ and try using the X2 icon just above the Reply box :wink:)

drop a perpendicular from (x,y,z) to the x,y plane … that gives you tanθ, then φ wil be the usual planar polar coordinate :wink:
 
  • #3
HallsofIvy
Science Advisor
Homework Helper
43,010
969
You can, of course, calculate the vector from A to B just by subtracting coordinates. You can then calculate the unit vector by dividing each component by the length of the vector.

And the components of that unit vector are the "direction cosines". That is, if the unit vector is [itex]a\vec{i}+ b\vec{j}+ c\vec{k}[/itex] and the angle the vector makes with the x-axis is [itex]\theta[/itex], the angle the vector makes with the y-axis is [itex]\phi[/itex], and the angle the vector makes with the z-axis is [itex]\psi[/itex], then

[tex]a= cos(\theta)[/tex],
[tex]b= cos(\phi)[/tex],
and
[tex]c= cos(\psi)[/tex]

Of course, those angles are not independent: [itex]cos^2(\theta)+ cos^2(\phi)+ cos^2(\psi)= 1[/itex] so it is sufficient to know two.

If I understand you correctly, the "polar angle" is [itex]\theta[/itex] and the "azimuthal angle" is [itex]\psi[/itex].
 
  • #4
susantha
6
0
Thank you for your valuable comments. Now I guess I have the algorithm to find two angles (teta and phi) of a given 3d vector. Here is the algorithm:

// First find the vector AB. (vector AB= vector B - vector A). B=(x1,y1,z1) and A=(x2,y2,z2)
// vector AB =(del_x, del_y, del_z);
del_x = x1-x2;
del_y = y1-y2;
del_z = z1-z2;
// Then we can find the magnitude of the vector AB,
r=sqrt (del_x^2 + del_y^2 +del_z^2);
s = sqrt ( del_x^2 + del_y^2 );
teta = arccos(del_z / r); // teta is the polar angle

//to find the azimuth angle,
if (del_x > 0)
phi= arcsin( del_y / s);
else
phi=pi - arcsin( del_y / s);

if (del_x > 0 && del_y <0 )
phi= pi - phi;

The last if condition is to make sure the phi has positive values between zero and 2*pi.

Thanks again for all comments.
Susantha
 

Suggested for: Angles of a 3D vector

Replies
4
Views
2K
Replies
3
Views
4K
Replies
0
Views
4K
  • Last Post
Replies
5
Views
1K
Replies
5
Views
7K
  • Last Post
Replies
4
Views
625
Replies
4
Views
4K
Replies
10
Views
3K
  • Last Post
Replies
14
Views
906
  • Last Post
Replies
0
Views
1K
Top