user9305731
user9305731

Reputation:

Order of Concatenation for Transform in Swift Playgrounds

While using playground I discovered somewhat of an unexpected scenario

I was translating a square(w: 100, h: 100) from (0,0) to (150, 150) and rotating it .pi. I was using concatenation to translate and rotate the square at the same time, so this came as a surprise but when I switched what order I was calling the translation and rotation, the square would move different ways

When I rotated the square before I translated it, the square would move from(0,0) to (150, 150), as predicted

However, when I translated before I rotated the square, the square would move from (0,0) and rotate up and left off the screen, which to me doesn't logically make sense, can someone try and explain this to me?

Code from the Playground

Two Lines of Code Changed

Upvotes: 0

Views: 226

Answers (1)

matt
matt

Reputation: 535850

Because of the nature of matrix algebra, the order in which transforms are applied in concatenating (aka CGAffineTransformConcat) is the opposite of the order in which you would apply them one by one to get the same effect.

Upvotes: 1

Related Questions