3

I have the X,Y,Z and W components of a Quaternion through time, in 4 separated vectors.

  QW             1x346             2768  double       
  QX             1x346             2768  double
  QY             1x346             2768  double
  QZ             1x346             2768  double              

I want to convert to euler angles in order to plot the 3 euler components in three different subplots through time, so I need to have 3 vectors like these.

  heading(t)          1x346 
  attitude(t)         1x346 
  bank(t)             1x346 

Is there an inmediate way in matlab to get this (I mean a function with input my 4 vectors and output the above 3 vectors) or do I have to write some code to make the conversion for each timestep? Thanks in advance.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164

1 Answers1

6

I do not think there is a built in Matlab function to perform what you want.

However, there is a function in the Mathworks user community which I believe is what you are looking for. spinCalc This will convert between the various rotation types DCM, Euler angles, Euler vectors, and Quaternions.

Please note this comment from the above post regarding Euler Angle Sets and which rotation sequence you are using.

When converting data to Euler angles, you MUST make sure the orientation you are translating is not near a singularity. Singular Euler sets are orientations which cannot be uniquely converted to 3 variables in that particular rotation order. The singular sets are as follows:

Type 1 Rotations: 123 - 132 - 213 - 231 - 321 - 312 Singular if second rotation angle is -90 or 90 degrees.

Type 2 Rotations: 121 - 131 - 212 - 232 - 313 - 323 Singular if second rotation angle is 0 or 180 degrees.

Aero Engy
  • 3,588
  • 1
  • 16
  • 27
  • +1. Thanks for your answer, it looks interesting, tomorrow I will check it thoroughly. I have a good documentation about quaternions and rotations so I'll be careful. In case you don't know check this page, you have everything (except a good index or browser haha) about 3D space! http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/ – Jav_Rock Jan 17 '12 at 18:19
  • 1
    @Jav_Rock Also as a note about the spinCalc function: You requested heading, attitude, and bank so I think you should call the spinCalc with the 'QtoEA123' option. Since those should correspond to x, y, z rotations. – Aero Engy Jan 17 '12 at 22:14
  • I am trying the codes, I like the funtion but still I cannot get the same results of conversion as in this link: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/ – Jav_Rock Jan 18 '12 at 09:01
  • @Jav_Rock I haven't looked over the details of spinCalc conversion processes but my first thought would be to make sure you are putting the Quaterions in the correct order. The function assumes the Q(x,y,z,w) notation. Some people use the Q(w,x,y,z) notation. So are you defining Q as `Q = [QX(:) QY(:) QZ(:) QW(:)];` If you are then ... inspecting spinCalc's method would be in required. Also try the QtoEA321 as an alternate to QtoEA123 ... I may have got the order backwards in my previous comment. – Aero Engy Jan 18 '12 at 18:23
  • It wasn't that, it is the angle, which is set between 0 and 360 instead of -180 and 180. A matter of standards, but I can change the function, thanks! – Jav_Rock Jan 18 '12 at 21:23