Dann (nehmen wir die Koordinaten vor der Drehung an: ( x0, y0, z0 ) , die Koordinaten nach der Drehung: ( x3, y3, z3 )):
- # Quaternion in Euler-Winkel konvertiert
- def quat2eular (w, x, y, z):
- # Kartesisches Koordinatensystem
- roll = math.atan2 (2 * (w * x + y * z), 1 - 2 * (x * x + y * y))
- Tonhöhe = math.asin (2 * (w * y - x * z))
- yaw = math.atan2 (2 * (w * z + x * y), 1 - 2 * (y * y + z * z))
- # Direct3D, die X- Achse der kartesischen Koordinaten wird zur Z- Achse , die Y- Achse wird zur X- Achse und die Z- Achse wird zur Y- Achse
- # roll = math.atan2 (2 * (w * z + x * y), 1 - 2 * (z * z + x * x))
- # pitch = math.asin (2 * (w * x - y * z))
- # yaw = math.atan2 (2 * (w * y + z * x), 1 - 2 * (x * x + y * y))
- # In einen Winkel umgewandelt
- Rückgabe math.degrees (Gieren), math.degrees (Tonhöhe), math.degrees (Rolle)
- # Eulerwinkel werden in Quaternionen umgewandelt , Rotationssequenz ist ZYX ( Gierwinkel Gieren , Nickwinkel Pitch, Rollwinkel der Rolle)
- def eular2quat (Gieren, Neigen , Rollen):
- #Beachten Sie, dass dies zuerst in Bogenmaß konvertiert werden muss , da alle Dreiecksberechnungen hier Bogenmaß verwenden .
- yaw = math.radians (yaw)
- Tonhöhe = math.radians (Tonhöhe)
- roll = math.radians (roll)
- en , sy = math.cos (Gieren * 0,5 ), math.sin (Gieren * 0,5 )
- cp, sp = math.cos (Tonhöhe * 0,5 ), math.sin (Tonhöhe * 0,5 )
- cr, sr = math.cos (roll * 0,5 ), math.sin (roll * 0,5 )
- # Kartesisches Koordinatensystem
- w = c * ep * cs + r * sp * sy
- x = r * ep * cy - er * sp * sy
- y = cr * sp * cy + sr * cp * sy
- z = c * ep * sy - r * sp * cs
- # Direct3D, die X- Achse der kartesischen Koordinaten wird zur Z- Achse , die Y- Achse wird zur X- Achse und die Z- Achse wird zur Y- Achse
- # W 'cp = CR + SR * Cy * sp * sy
- # X = c * sp * cs + SR 'cp * sy
- # y = cr * cp * sy - sr * sp * cy
- # Z = r * CP * cy - er sp * sy
- return w, x, y, z
- if __name__ == "__main__":
- y, p, r = (10, 20 , 30 )
- q0, q1, q2, q3 = eular2quat (y, p, r)
- Drucken (q0, q1, q2, q3)
- y, p, r = quat2eular (q0, q1, q2, q3)
- q0, q1, q2, q3 = eular2quat (y, p, r)
- Drucken (q0, q1, q2, q3)
- print (quat2eular (q0, q1, q2, q3))