# Math Help - Calculating an angle in 3D coordinates

1. ## Calculating an angle in 3D coordinates

Hi

A vector has x, y, and z components of Ax, Ay, and Az. I want to calculate the angle between the vector and the x-axis (call it theta).

I work out the following:

sqrt(Ax*Ax + Az*Az) * cos(theta) = Az
sqrt(Ax*Ax + Az*Az) * sin(theta) = Ax

So that theta = arctan(Ax/Az).

But the notes I have state a different equation for theta:

theta = arctan(Ax / sqrt(Az*Az + Ay*Ay))

Could you please tell me where I am going wrong, and how the notes get the answer?

Thanks.

2. ## Re: Calculating an angle in 3D coordinates

You have two vectors, one is a $= (Ax,Ay,Az)$ and the second b $=(1,0,0)$, now use:

$\theta = \arccos\frac{a \cdot b} {|a||b|}$

3. ## Re: Calculating an angle in 3D coordinates

Thanks. I didn't think about using that...but I'm still not getting it right.

To find the angle the vector makes with the x-axis, we can consider only the x and z components (Ax and Az).

Using the equation above: theta = arccos(Ax / sqrt(Ax*Ax + Az*Az))

Whereas in the notes it's Ay*Ay on denominator, rather than Ax*Ax...

4. ## Re: Calculating an angle in 3D coordinates

Originally Posted by algorithm
Thanks. I didn't think about using that...but I'm still not getting it right.

To find the angle the vector makes with the x-axis, we can consider only the x and z components (Ax and Az).

Using the equation above: theta = arccos(Ax / sqrt(Ax*Ax + Az*Az))

Whereas in the notes it's Ay*Ay on denominator, rather than Ax*Ax...

$\theta = \arccos\frac{a \cdot b} {|a||b|}$

$=\arccos\frac{(Ax,Ay,Az)\cdot (1,0,0)} {|(Ax,Ay,Az)||(1,0,0)|}$

$=\arccos\frac{(Ax\cdot 1+Ay\cdot 0+Az\cdot 0)} {\sqrt{(Ax)^2+(Ay)^2+(Az)^2}\sqrt{1^2+0^2+0^2}}$

$=\arccos\frac{Ax} {\sqrt{(Ax)^2+(Ay)^2+(Az)^2}}$

$=\arccos\frac{x} {\sqrt{x^2+y^2+z^2}}$

5. ## Re: Calculating an angle in 3D coordinates

Thanks. The notes I have give a solution using arctan instead of arccos. The answer given is: theta = arctan(Ax / sqrt(Az*Az + Ay*Ay))

The equation they give is on page 4: http://www.freescale.com/files/senso...ote/AN3461.pdf

How can I get from your solution to the one in the notes?

6. ## Re: Calculating an angle in 3D coordinates

Originally Posted by Also sprach Zarathustra
$\theta = \arccos\frac{a \cdot b} {|a||b|}$

$=\arccos\frac{(Ax,Ay,Az)\cdot (1,0,0)} {|(Ax,Ay,Az)||(1,0,0)|}$

$=\arccos\frac{(Ax\cdot 1+Ay\cdot 0+Az\cdot 0)} {\sqrt{(Ax)^2+(Ay)^2+(Az)^2}\sqrt{1^2+0^2+0^2}}$

$=\arccos\frac{Ax} {\sqrt{(Ax)^2+(Ay)^2+(Az)^2}}$

$=\arccos\frac{x} {\sqrt{x^2+y^2+z^2}}$
You are assuming, are you not, that "A" is a single constant multiplying the vector <x, y, z>? I would have interpreted it merely to mean that " $A_x$", " $A_y$", and " $A_z$" the x, y, and z components, respectively, of the vector.

7. ## Re: Calculating an angle in 3D coordinates

Originally Posted by algorithm
Hi

A vector has x, y, and z components of Ax, Ay, and Az. I want to calculate the angle between the vector and the x-axis (call it theta).

I work out the following:

sqrt(Ax*Ax + Az*Az) * cos(theta) = Az
sqrt(Ax*Ax + Az*Az) * sin(theta) = Ax

So that theta = arctan(Ax/Az).

But the notes I have state a different equation for theta:

theta = arctan(Ax / sqrt(Az*Az + Ay*Ay))

Could you please tell me where I am going wrong, and how the notes get the answer?

Thanks.
1. Draw a sketch (see attachment).

2. You'll find the angle $\theta$ in a right triangle with
the hypotenuse $|\vec v|$
the opposite leg $k= \sqrt{A_y^2+A_z^2}$
the adjacent leg $A_x$

3. So to me the value of $\theta$ is calculated by:

$|\theta|=\arctan\left(\dfrac{\sqrt{A_y^2+A_z^2}}{| A_x|} \right)$

which is the reciprocal value of the given solution (?)

8. ## Re: Calculating an angle in 3D coordinates

@HallsOfIvy: Sorry, I mean that Ax is the actual x component, rather than a constant multiplying x.

9. ## Re: Calculating an angle in 3D coordinates

@earboth: Thanks for your diagram, it made it much clearer. I get the same result as you...

I guess the notes are wrong. One of my answers agrees with the notes, whilst for the other two (angles phi and rho), I get the inverse of the expression inside arctan.