Get relative translation and rotation of two models

I am unfortunately not well acquanted with euler angles. This might be a quite uninformed question.

So i get the euler rotations in ZXY order above. Translation i get from the 4x4 matrix.
For instance as above: i perform a model registration through ALPACA, it gives me a matrix. From this matrix i get the ZXY of euler angles. Now when i put these angles in the ZXY order into a new transformation (with the translational component of the 4x4 matrix) to see if i would again get the same allignment, this does not occur. I know this is a flaw in my understanding of Euler angles, however i cannot seem to find a answer to this.

Im very gratefull for the time you’ve taken to answer my questions.

Conversion from orientation matrix to Euler angles is not well defined (the same orientation may be represented with various combination of rotations). However, conversion from Euler angles to orientation matrix should always provide the same matrix as the one that the Euler angles are computed from.

You need to play a bit with the order of rotation axes, but the vtkTransform class can be used for both conversions. For example:

print("=============================")
import random
random.random()
rx = random.random() * 180 - 90
ry = random.random() * 180 - 90
rz = random.random() * 180 - 90
transform = vtk.vtkTransform()
transform.RotateZ(rz)
transform.RotateX(rx)
transform.RotateY(ry)
print(f"Euler angles (original): {rx}, {ry}, {rz}")
print(f"Matrix (original): {transform.GetMatrix()}")

print("--------------")
[rx2, ry2, rz2] = transform.GetOrientation()
transform2 = vtk.vtkTransform()
transform2.RotateZ(rz2)
transform2.RotateX(rx2)
transform2.RotateY(ry2)
print(f"Euler angles (computed from matrix): {rx2}, {ry2}, {rz2}")
print(f"Matrix (from computed Euler angles): {transform2.GetMatrix()}")

Output:

=============================
Euler angles (original): 31.012387417137504, -0.18095415482437716, 65.38408784135231
Matrix (original): vtkMatrix4x4 (000001BBE31DC5C0)
  Debug: Off
  Modified Time: 243130
  Reference Count: 2
  Registered Events: (none)
  Elements:
    0.418011 -0.779167 0.467082 0 
    0.908438 0.356992 -0.217478 0 
    0.00270679 0.515223 0.857052 0 
    0 0 0 1 
--------------
Euler angles (computed from matrix): 31.012387417137504, -0.18095415482437716, 65.38408784135231
Matrix (from computed Euler angles): vtkMatrix4x4 (000001BBE31DBC60)
  Debug: Off
  Modified Time: 243145
  Reference Count: 2
  Registered Events: (none)
  Elements:
    0.418011 -0.779167 0.467082 0 
    0.908438 0.356992 -0.217478 0 
    0.00270679 0.515223 0.857052 0 
    0 0 0 1