Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
vector's angle to coordinate axes

Subject: vector's angle to coordinate axes

From: Toni

Date: 25 Jan, 2012 13:51:10

Message: 1 of 3


Hello all,

i have perhaps a silly question, which i would like to have some confirmation to, since i haven't been able to find any.

So if i have an arbitrary vector, e.g v1 = [0.21 -0.8 0.56].

Then if I'd like to know the angle this vector makes with the x,y and z axis,
is it something like this:

        zang = acos(dot(v1,[0 0 1]'))*(180/pi);
        xang = acos(dot(v1,[1 0 0]'))*(180/pi);
        yang = acos(dot(v1,[0 1 0]'))*(180/pi);



Huge thanks!

Subject: vector's angle to coordinate axes

From: Torsten

Date: 25 Jan, 2012 14:36:15

Message: 2 of 3

On 25 Jan., 14:51, "Toni " <annihilaa...@yahoo.com> wrote:
> Hello all,
>
> i have perhaps a silly question, which i would like to have some confirmation to, since i haven't been able to find any.
>
> So if i have an arbitrary vector, e.g v1 = [0.21 -0.8 0.56].
>
> Then if I'd like to know the angle this vector makes with the x,y and z axis,
> is it something like this:
>
>         zang = acos(dot(v1,[0 0 1]'))*(180/pi);
>         xang = acos(dot(v1,[1 0 0]'))*(180/pi);
>         yang = acos(dot(v1,[0 1 0]'))*(180/pi);
>
> Huge thanks!

cos(theta) = (u*v)/(||u||*||v||)
If v1 from above is a unit vector, your formula from above is correct.

Best wishes
Torsten.

Subject: vector's angle to coordinate axes

From: Roger Stafford

Date: 25 Jan, 2012 20:10:10

Message: 3 of 3

"Toni " <annihilaatio@yahoo.com> wrote in message <jfp1ce$kpr$1@newscl01ah.mathworks.com>...
> So if i have an arbitrary vector, e.g v1 = [0.21 -0.8 0.56].
> Then if I'd like to know the angle this vector makes with the x,y and z axis,
> is it something like this:
> zang = acos(dot(v1,[0 0 1]'))*(180/pi);
> xang = acos(dot(v1,[1 0 0]'))*(180/pi);
> yang = acos(dot(v1,[0 1 0]'))*(180/pi);
- - - - - - - -
  To avoid loss of accuracy when v1 is nearly parallel to one of the three axes, you can use 'atan2' instead of 'acos':

 xany = 180/pi*atan2(sqrt(v1(2)^2+v1(3)^2),v1(1));
 yany = 180/pi*atan2(sqrt(v1(3)^2+v1(1)^2),v1(2));
 yany = 180/pi*atan2(sqrt(v1(1)^2+v1(2)^2),v1(3));

This does not require that v1 be of unit length.

  Note: The arc cosine curve has an infinite derivative at +1 and -1, which introduces markedly larger round off errors there.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us