Umwandlung von Euler in Matrix und Matrix in Euler

Ich versuche, eine 3D-Rotation, die in Form von Euler-Winkeln beschrieben wird, mit .NET / C # in eine Matrix und wieder zurück zu konvertieren. Meine Konventionen sind:

linkshändiges System (x rechts, y oben, z vorwärts)Reihenfolge der Rotationen: Überschrift um y, Tonhöhe um x, Bank um zUmdrehungen sind positiv, wenn die linke Regel verwendet wird (Daumen zeigt auf + unendlich)

Mein Prozess ist:

Euler zur Matrix (Ich habe den x, y, z-Übersetzungsteil zur Vereinfachung entfernt.)

Matrix3D matrix = new Matrix3D() {
    M11 =   cosH * cosB - sinH * sinP * sinB,
    M12 = - sinB * cosP,
    M13 =   sinH * cosB + cosH * sinP * sinB,
    M21 =   cosH * sinB + sinH * sinP * cosB,
    M22 =   cosB * cosP,
    M23 =   sinB * sinH - cosH * sinP * cosB,
    M31 = - sinH * cosP,
    M32 = - sinP,
    M33 =   cosH * cosP,
};

Matrix zu Euler

const double RD_TO_DEG = 180 / Math.PI;            
double h, p, b; // angles in degrees

// extract pitch
double sinP = -matrix.M23;            
if (sinP >= 1) {
    p = 90; }       // pole
else if (sinP <= -1) {
    p = -90; } // pole
else {
    p = Math.Asin(sinP) * RD_TO_DEG; }             

// extract heading and bank
if (sinP < -0.9999 || sinP > 0.9999) { // account for small angle errors
    h = Math.Atan2(-matrix.M31, matrix.M11) * RD_TO_DEG;
    b = 0; }
else {
    h = Math.Atan2(matrix.M13, matrix.M33) * RD_TO_DEG;
    b = Math.Atan2(matrix.M21, matrix.M22) * RD_TO_DEG; }

Es muss falsch sein. Wenn ich 3 Winkel nehme, konvertiere ich sie in eine Matrix und konvertiere die Matrix zurück in Winkel, wobei das Ergebnis von den Anfangswerten abweicht.

Ich habe mehrere Websites mit unterschiedlichen Formeln durchsucht, angefangen mit euclideanspace.com, bin aber jetzt völlig verloren und kann die richtigen Berechnungen nicht finden. Ich freue mich über eine kleine Hilfe. Ist ein Mathematiker an Bord?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage