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:
euler angles?

Subject: euler angles?

From: Rafael Herrejon

Date: 26 Mar, 2009 22:53:01

Message: 1 of 8

Hello

I need some help to find the rotation angle of a matrix with respect to a general (world) coordinate.
Lets say i have the gravity vector gv=[gx,gy,gz], how can i obtain the euler angles of the rotation matrix R?
gv'=R*[0,0,g]
Previously, Bruno teached me how to obtain a set of euler angles, but the euler angles obtained "th2" are different than the originals "th1" and when they are ploted, they dont seem to refer to the same rotation. I would highly appreciate any comment.

close all
clear all;
clc
g=9.81;
gworld=[0;0;g/2];

psi1=-3.1350;
theta1=-0.0280;
phi1=3.1263;

th=[psi1,theta1,phi1]

rotx=[1 0 0; %define rotations in axes
    0 cos(psi1), -sin(psi1);
    0 sin(psi1), cos(psi1);];
roty=[cos(theta1), 0, sin(theta1);
             0, 1, 0;
    -sin(theta1), 0, cos(theta1)];
rotz=[cos(phi1), -sin(phi1),0;
    sin(phi1),cos(phi1),0;
    0 , 0, 1;];

rotmat=[rotz*roty*rotx] %rotation matrix first in x, then y and finally z
vect1=rotmat*gworld

vectorin1=cross(gworld,vect1)/(norm(gworld)*norm(vect1));
nv1=min(max(norm(vectorin1),-1),1);
theta2=asin(nv1);
if dot(gworld,vect1)<0
    theta2=pi-theta2;
end
rotmat2=rodrigues(vectorin1/nv1*theta2)
psi2=atan2(rotmat2(3,2)/cos(theta2),rotmat2(3,3)/cos(theta2)); %%Rot_x
phi2=atan2(rotmat2(2,1)/cos(theta2),rotmat2(1,1)/cos(theta2)); %%Rot_z

vect2=rotmat2*gworld
th=[psi2,theta2,phi2]

 
figure;
plot3(0,0,0)
hold on
grad2rad=pi/180;
point1o= [0;0;0];
point2o= [0;0;.3];
point3o= [0;.3;0];
point4o= [.3;0;0];

plot3([point1o(1),point2o(1)],[point1o(2),point2o(2)],[point1o(3),point2o(3)],'r','linewidth',2);% plot Z axis
plot3([point1o(1),point3o(1)],[point1o(2),point3o(2)],[point1o(3),point3o(3)],'r','linewidth',2);% plot Y axis
plot3([point1o(1),point4o(1)],[point1o(2),point4o(2)],[point1o(3),point4o(3)],'r','linewidth',2);% plot X axis
text(point2o(1),point2o(2),point2o(3),'Z_0');
text(point3o(1),point3o(2),point3o(3),'Y_0');
text(point4o(1),point4o(2),point4o(3),'X_0');
text(point1o(1),point1o(2),point1o(3),'O_0');

point1th1= (rotmat'*(point1o));
point2th1= (rotmat'*(point2o));
point3th1= (rotmat'*(point3o));
point4th1= (rotmat'*(point4o));
plot3([point1th1(1),point2th1(1)],[point1th1(2),point2th1(2)],[point1th1(3),point2th1(3)],'c','linewidth',2);% plot Z axis
plot3([point1th1(1),point3th1(1)],[point1th1(2),point3th1(2)],[point1th1(3),point3th1(3)],'c','linewidth',2);% plot Y axis
plot3([point1th1(1),point4th1(1)],[point1th1(2),point4th1(2)],[point1th1(3),point4th1(3)],'c','linewidth',2);% plot X axis
text(point2th1(1),point2th1(2),point2th1(3),'Z_{th1}');
text(point3th1(1),point3th1(2),point3th1(3),'Y_{th1}');
text(point4th1(1),point4th1(2),point4th1(3),'X_{th1}');
text(point1th1(1),point1th1(2),point1th1(3),'O_{th1}');

point1th2= (rotmat2'*(point1o));
point2th2= (rotmat2'*(point2o));
point3th2= (rotmat2'*(point3o));
point4th2= (rotmat2'*(point4o));
plot3([point1th2(1),point2th2(1)],[point1th2(2),point2th2(2)],[point1th2(3),point2th2(3)],'y--','linewidth',2);% plot Z axis
plot3([point1th2(1),point3th2(1)],[point1th2(2),point3th2(2)],[point1th2(3),point3th2(3)],'y-.','linewidth',2);% plot Y axis
plot3([point1th2(1),point4th2(1)],[point1th2(2),point4th2(2)],[point1th2(3),point4th2(3)],'y-.','linewidth',2);% plot X axis
text(point2th2(1),point2th2(2),point2th2(3),'Z_{th2}');
text(point3th2(1),point3th2(2),point3th2(3),'Y_{th2}');
text(point4th2(1),point4th2(2),point4th2(3),'X_{th2}');
text(point1th2(1),point1th2(2),point1th2(3),'O_{th2}');

axis equal

Subject: euler angles?

From: Rafael Herrejon

Date: 2 Apr, 2009 05:40:04

Message: 2 of 8

snip

anybody out there who could help me? thank you very much!

Subject: euler angles?

From: Bruno Luong

Date: 3 Apr, 2009 08:32:02

Message: 3 of 8

"Rafael Herrejon" <rafael.erasethis@ic.is.tohoku.ac.jp> wrote in message <gr1j3k$738$1@fred.mathworks.com>...
> snip
>
> anybody out there who could help me? thank you very much!

I have not read through your code. But I though it is clear the last time we discussed that there is no unique rotation if only one vector and its mapping is known.

In order obtain the rotation, we need more information. Do you have any new input?

Bruno

Subject: euler angles?

From: Rafael Herrejon

Date: 3 Apr, 2009 09:39:01

Message: 4 of 8

> > snip
> >
> > anybody out there who could help me? thank you very much!
>
> I have not read through your code. But I though it is clear the last time we discussed that there is no unique rotation if only one vector and its mapping is known.
>
> In order obtain the rotation, we need more information. Do you have any new input?
>
> Bruno

Hello Bruno
Thanks for your answer, in the general coordinates the vector of gravity is always "negative", about the mapped vector [gx,gy,gz], i have the information if the gz should be upwards(opposite to the gravity) or downwards.

Regards
Rafael

Subject: euler angles?

From: Rafael Herrejon

Date: 3 Apr, 2009 10:30:03

Message: 5 of 8

"Rafael Herrejon" <rafael.erasethis@ic.is.tohoku.ac.jp> wrote in message <gr4lfl$p4o$1@fred.mathworks.com>...
> > > snip
> > >
> > > anybody out there who could help me? thank you very much!
> >
> > I have not read through your code. But I though it is clear the last time we discussed that there is no unique rotation if only one vector and its mapping is known.
> >
> > In order obtain the rotation, we need more information. Do you have any new input?
> >
> > Bruno
>
> Hello Bruno
> Thanks for your answer, in the general coordinates the vector of gravity is always "negative", about the mapped vector [gx,gy,gz], i have the information if the gz should be upwards(opposite to the gravity) or downwards.
>
> Regards
> Rafael
Sorry, i meant i know if the z-axis of the mapped vector is upwards or downwards

Subject: euler angles?

From: Bruno Luong

Date: 3 Apr, 2009 10:43:02

Message: 6 of 8

"Rafael Herrejon" <rafael.erasethis@ic.is.tohoku.ac.jp> wrote in message <gr4ofb$l0r$1@fred.mathworks.com>...

> Sorry, i meant i know if the z-axis of the mapped vector is upwards or downwards

Sight... Let's make it clear one more time: a *single* vector and its mapping (by rotating by R) are *not* enough to calculate R.

Bruno

Subject: euler angles?

From: Rafael Herrejon

Date: 8 Apr, 2009 09:43:02

Message: 7 of 8

> > Sorry, i meant i know if the z-axis of the mapped vector is upwards or downwards
>
> Sight... Let's make it clear one more time: a *single* vector and its mapping (by rotating by R) are *not* enough to calculate R.
>
> Bruno


im sorry for my ignorance.. what do i need to be able to calculate the rotation R?
is it possible to calculate uniquely R if i have another vector parallel to the ground?
Thank you very much

Rafael

Subject: euler angles?

From: Bruno Luong

Date: 8 Apr, 2009 11:00:18

Message: 8 of 8

"Rafael Herrejon" <rafael.erasethis@ic.is.tohoku.ac.jp> wrote in message <grhrj6$lgt$1@fred.mathworks.com>...
>
> im sorry for my ignorance.. what do i need to be able to calculate the rotation R?
> is it possible to calculate uniquely R if i have another vector parallel to the ground?

I don't understand the sentence " i have another vector parallel to the ground". There is always a (even many) vector parallel to the ground!!!

One additional equation is missing to estimate R. It can be anything such as
- Rotation axis is perpendicular to a fixed face (or parallel to something),
- a known value of the rotation angle
- mapping of *two* vectors,
- etc...

A sign of an input is not really an additional information, because it's already there.

Bruno

Tags for 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