Jake Batsuuri
2 min readMar 6, 2023

--

# Diagonal Matrices

- First of all, diagonal matrices are zero everywhere except the main diagonal

- But they can also be 0’s on the main diagonal too

- So mistake 1

- A diagonal matrix is sometimes called a [scaling matrix](https://en.wikipedia.org/wiki/Scaling_matrix), since matrix multiplication with it results in changing scale (size). Its determinant is the product of its diagonal values.

- Look at this scaling transformation done by Apple’s ARKit

- All done one the main diagonal

- Next mistake, yes you are right dot product → scalar

- While Hadamard product → vector

- In other words, dot product is the sum of the entries of the Hadamard product

- Sorry about that, fixed, thanks for your careful examination

[ios - What are the first two columns in SCNMatrix4 - Stack Overflow](https://www.notion.so/ios-What-are-the-first-two-columns-in-SCNMatrix4-Stack-Overflow-a887b873d7334b84a594d6b1441bc4a2)

[What are the first two columns in SCNMatrix4](https://stackoverflow.com/questions/48264518/what-are-the-first-two-columns-in-scnmatrix4)

SCNMatrix4 is the 3d [transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix). In short:

```

M = T * R * S

```

Translation by (tx, ty, tz):

```

┌ ┐

T = | 1 0 0 tx |

| 0 1 0 ty |

| 0 0 1 tz |

| 0 0 0 1 |

└ ┘

```

Scale by (sx, sy, sz):

```

┌ ┐

S = | sx 0 0 0 |

| 0 sy 0 0 |

| 0 0 sz 0 |

| 0 0 0 1 |

└ ┘

```

Rotation by (rx, ry, rz):

```

R = ZYX

┌ ┐

X = | 1 0 0 0 |

| 0 cos(rx) -sin(rx) 0 |

| 0 sin(rx) cos(rx) 0 |

| 0 0 0 1 |

└ ┘

┌ ┐

Y = | cos(ry) 0 sin(ry) 0 |

| 0 1 0 0 |

| -sin(ry) 0 cos(ry) 0 |

| 0 0 0 1 |

└ ┘

┌ ┐

Z = | cos(rz) -sin(rz) 0 0 |

| sin(rz) cos(rz) 0 0 |

| 0 0 1 0 |

| 0 0 0 1 |

└ ┘

```

--

--

No responses yet