# Does order of concatenation affect AffineTransforms?

posted 2 years ago

I'm working with AffineTransforms, and am confused by one aspect of their behavior. It appears that the order in which two sequential concatenations are executed effects the final result. Here's a fragment of code to illustrate the concept:

This code has dramatically different results if the two concatenations are reversed in order. I'm not asking anybody to fix my code; I want to understand what's going on. Is it really true that the order of concatenations affects the final result? From my understanding of matrix multiplication, it shouldn't. Have I missed something here?

This code has dramatically different results if the two concatenations are reversed in order. I'm not asking anybody to fix my code; I want to understand what's going on. Is it really true that the order of concatenations affects the final result? From my understanding of matrix multiplication, it shouldn't. Have I missed something here?

Piet Souris

Rancher

Posts: 1631

36

posted 2 years ago

hi Chris,

yes, the order DOES matter.

Each AffineTransformation is internally represented by a 3 x 3 matrix.

If you have two of them, say R and T, then the resulting matrix is

obtained by applying a matrix multiplication.

So, if your order is: R, then T, then the result is the matrix R * T.

If the order is: first T, then R, then the resulting matrix is T * R.

In general, matrix multiplications are not commutative, i.e:

R * T <> T * R.

See the API for more information about the matrix representation of a

AffineTransform.

Greetz,

Piet

yes, the order DOES matter.

Each AffineTransformation is internally represented by a 3 x 3 matrix.

If you have two of them, say R and T, then the resulting matrix is

obtained by applying a matrix multiplication.

So, if your order is: R, then T, then the result is the matrix R * T.

If the order is: first T, then R, then the resulting matrix is T * R.

In general, matrix multiplications are not commutative, i.e:

R * T <> T * R.

See the API for more information about the matrix representation of a

AffineTransform.

Greetz,

Piet

posted 2 years ago

Thanks much, Piet. From somewhere in the ancient history of my college years (alongside the courses on alchemy and phrenology), I had remembered -- wrongly -- that matrix multiplication is commutative. That was the source of my confusion. Now that you've set me straight, I can read that documentation with greater clarity of understanding.