import numpy as np import math rx = math.radians(-60.0) rz = math.radians(45.0) cosX, sinX = math.cos(rx), math.sin(rx) cosZ, sinZ = math.cos(rz), math.sin(rz) # Original code rotation matrix rot = np.array([ [cosZ, -sinZ*cosX, sinZ*sinX, 0], [sinZ, cosZ*cosX, -cosZ*sinX, 0], [0, sinX, cosX, 0], [0, 0, 0, 1] ]) print("Original rot:\\n", rot) # Correct orbit Rx @ Rz rot_correct = np.array([ [cosZ, -sinZ, 0, 0], [cosX*sinZ, cosX*cosZ, -sinX, 0], [sinX*sinZ, sinX*cosZ, cosX, 0], [0, 0, 0, 1] ]) print("Rx @ Rz:\\n", rot_correct)