# Setting directional cosines

**URL:** https://discourse.itk.org/t/setting-directional-cosines/6156
**Category:** Beginner Questions
**Created:** [August 22, 2023, 3:11pm UTC](https://discourse.itk.org/t/setting-directional-cosines/6156 "2023-08-22T15:11:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Krishna\_Nanda](https://discourse.itk.org/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@Krishna\_Nanda](https://discourse.itk.org/u/Krishna_Nanda)
#### Post date: [August 22, 2023, 3:11pm UTC](https://discourse.itk.org/t/setting-directional-cosines/6156/1 "2023-08-22T15:11:12Z")

</div>

Hello,

I am a little unclear on how the directional cosines are set to create a new Simple ITK image. I understand that they should be in row major order. Is this correct: If we take a 2D example, the unit vector along a row (across columns) would go first and the unit vector along a column (across rows) would go second? If so, I am a bit confused with the 2D brain image example in the fundamental concepts guide. There, when the image is not tilted (the one on the right), the directional cosines are (1,0,0,1), which is essentially (direction cosine along a row, directional cosine along a column), i.e., (x axis direction, y axis direction). But when the image is tilted (left image), I would think the cosines would be (0.7, 0.7, -0.7, 0.7). I.e., the direction along row is now (0.7, 0.7) and direction along column is (-0.7, 0.7). This is different from what is written on the webpage, which is (0.7, -0.7, 0.7, 0.7). Can you kindly clarify if I am missing something here?

Also, in 3D, just to confirm, the row major order of cosines would be the following, correct?  
(directional cosine along increasing slice direction, directional cosine along row direction (across columns), directional cosine along column direction (across rows))

Thank you!

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [August 22, 2023, 4:53pm UTC](https://discourse.itk.org/t/setting-directional-cosines/6156/2 "2023-08-22T16:53:46Z")

</div>

Yeah, I think that’s a bug in the documentation. Here’s the test code that I made:

```
import SimpleITK as sitk

t = sitk.Euler2DTransform()
t.SetAngle(0.785398) # 45 degrees
print(t.GetMatrix())

```

and here’s the output:

```
(0.7071068967259817, -0.7071066656470943, 0.7071066656470943, 0.7071068967259817)

```

---

<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: [August 22, 2023, 5:20pm UTC](https://discourse.itk.org/t/setting-directional-cosines/6156/3 "2023-08-22T17:20:05Z")

</div>

Hello @Krishna_Nanda,

This isn’t a bug in the documentation. Please add the following line to @dchen’s code snippet and look at the matrix:

```auto
print(t)

```
