Multiplying transforms

Since my knowledge of matrix algebra is limited… Suppose I have several transformations of the same object - a translate, a rotate and a scale, for example - instead transforming the objects three times, can I just multiply the transforms and then transform once?

Thx,
–Mitch

In principle yes, but the order matters because matrix multiplication is not commutative.

Let’s say your scaling is tenfold in all directions and your translation is 10 units in x-direction

Then the matrices are:

scaling: 
| 10  0  0  0 |
|  0 10  0  0 |
|  0  0 10  0 |
|  0  0  0  1 |

translation:
|  1  0  0 10 |
|  0  1  0  0 |
|  0  0  1  0 |
|  0  0  0  1 |

S*T 
| 10  0  0 10 |
|  0 10  0  0 |
|  0  0 10  0 |
|  0  0  0  1 |

T*S
| 10  0  0 100 |
|  0 10  0   0 |
|  0  0 10   0 |
|  0  0  0   1 |

It’s quite logical really: if you translate first, and then scale (TS) then the translation is scaled as well. If you scale first and then translate (ST) the translation happens after scaling and is not scaled.

HTH,

Best wishes,

Menno

OK, thanks for the important info!

Interesting point, as most of the time you would probably not want the translation to scale, you do indeed need to to be careful with the order… :smile:

–Mitch

You are probably aware of this, but another important thing to keep in mind is that if you are going to rotate your object in place, it must first be translated back to the origin, rotated, then translated back to it’s original location. This is because rotations always take place around the origin and if you leave the object in it’s place away from the origin it will orbit the origin.