• ORBITER-FORUM will be temporarily closed at 2026-07-23 18:00 UTC while we complete some OF maintenance tasks. The amount of downtime is expected to take up to one hour, but probably less.

C++ Question How to get euler angles from quaternion.h

Topper

Addon Developer
Addon Developer
Donator
Joined
Mar 28, 2008
Messages
669
Reaction score
32
Points
43
Hello,
I found a quaternion class/header here.
Does somebody knows how to use the "toEuler" - method?

Code:
...
// -parameters : integer order- which will specify the order of the rotation, q- quaternion
// -return value : Euler angle
// -
template<class _Tp>
    void Quaternion<_Tp>::toEuler(_Tp e[3], int order)
{
  Quat q;

  q.w = 0;
  q.x = e[0];
  q.y = e[1];
  q.z = e[2];

  EulerAngles ea = Eul_FromQuat(q, order);

  w = ea.w;
  x = ea.x;
  y = ea.y;
  z = ea.z;
}

...

I want to get it working like this (just a check if the current yaw, pitch and bank can be shown):

Code:
    VESSEL * ptrVessel = oapiGetFocusInterface();
    Quaternion<double> q_setpoint(ptrVessel->GetYaw(), ptrVessel->GetPitch(), ptrVessel->GetBank(), 0);
    double e[3] = {0,0,0};
    q_setpoint.toEuler(e,0);
    mfdi.lineBuffer[0] << "Yaw:" <<  e[0] << " Pitch:" << e[1] << " Roll:" << e[2];
It seems that e[0],e[1] and e[2] are only used for reading.

So is there something wrong with this header file???
And what does the order value means?
 
Last edited:
What is the contents of EulerAngles.h? It's included at the top of the quaternoin header.

That method appears to be wrong. I would change it to return a EulerAngles object, and add return ea to the end of the function.

As to the rotation order, it determines which axes to rotate around in which order. You need this because there are several Euler angle "solutions" for one quaternoin.

I would expect them to be defined in EulerAngles.h, in something like:
Code:
0: x,y,z
1: x,z,y
2: y,x,z
...etc
Where each of those is which rotations to do first.
 
What is the contents of EulerAngles.h?

Can be found here

I tried to return the eulerangle but I don't know how it's working.
I even don't understand why it has 4 elements instead of 3...
 
Last edited:
I've just lately been trying to convert Orbiters MATRIX3 to euler angles, without much success. So if you come up with something, I'd be interested in hearing it.
 
Back
Top