# How to change the order of rotation in SetComputeZYX()?

**URL:** <https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474>\
**Category:** Beginner Questions\
**Tags:** itk, cmake, registration\
**Created:** [November 9, 2022, 8:03am UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474 "2022-11-09T08:03:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![suzume](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@suzume](https://discourse.itk.org/u/suzume)\
**Post date:** [November 9, 2022, 8:03am UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/1 "2022-11-09T08:03:02Z")

</div>

I want to generate DRR from a CT image. I want the CT image to rotate in the order of the X, Y, Z axis. However, SetComputeZYX( ) only set the order ZYX/ZXY. How can I can set the order XYZ?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [November 9, 2022, 1:44pm UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/2 "2022-11-09T13:44:49Z")

</div>

You could [compose](https://itk.org/Doxygen/html/classitk_1_1CompositeTransform.html) two transforms, one ZXY with z angle of zero, and the another with x and y angles of zero.

---

<div class="post-metadata">

**Author:** ![suzume](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@suzume](https://discourse.itk.org/u/suzume)\
**Post date:** [November 10, 2022, 6:34am UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/3 "2022-11-10T06:34:14Z")

</div>

Thank you for your sincere reply! And I try to compose two transformations. However, the latter transform always works and the first transform seems to be not applied. I have found one of your replies before that may also be suitable for my question. Could you please introduce “computing internal data” in detail? “@pierrectl is trying to compose two `Euler3DTransform` s, if I understood correctly. Those are two transformations in the global domain. Computing internal data (matrix, center, translation) is probably easier with versor than affine. ”

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [November 10, 2022, 2:48pm UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/4 "2022-11-10T14:48:31Z")

</div>

> [@suzume](#):
>
> and the first transform seems to be not applied

If you share your code, there is a chance of receiving more help.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [November 10, 2022, 2:59pm UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/5 "2022-11-10T14:59:25Z")

</div>

Hello @suzume,

What you are asking for is just a different way of specifying the rotation matrix from that supported by the ITK API. If you want the rotation order to be XYZ then you can compute the matrix yourself and then use the transforms `SetMatrix` method.

Computing the XYZ matrix is easy to do, Python code below (translating to other lanaguges is pretty much a copy paste and adding some semicolons if relevant):

```auto
import numpy as np

ax = 0
ay = 0
az = np.deg2rad(90)

cx = np.cos(ax)
cy = np.cos(ay)
cz = np.cos(az)
sx = np.sin(ax)
sy = np.sin(ay)
sz = np.sin(az)

rotation = np.ndarray([3, 3])
rotation[0][0] = cz * cy
rotation[0][1] = cz * sy * sx - sz * cx
rotation[0][2] = cz * sy * cx + sz * sx

rotation[1][0] = sz * cy
rotation[1][1] = sz * sy * sx + cz * cx
rotation[1][2] = sz * sy * cx - cz * sx

rotation[2][0] = -sy
rotation[2][1] = cy * sx
rotation[2][2] = cy * cx

```

---

<div class="post-metadata">

**Author:** ![suzume](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@suzume](https://discourse.itk.org/u/suzume)\
**Post date:** [November 11, 2022, 1:08am UTC](https://discourse.itk.org/t/how-to-change-the-order-of-rotation-in-setcomputezyx/5474/6 "2022-11-11T01:08:03Z")

</div>

Thank you very much! I will try it!
