Rubber Ducking Affine Transforms
Why did my affine transform not work the way I expected it to?
Here’s a duck. Why a duck? Because they help programmers think about confusing things.
Here’s another duck.
They’re very similar. Mathematicians would say that they have an affine relationship, and can define an affine transform between them. Even if we don’t deeply understand all the math, affine transforms are a powerful way to manipulate images and views in our apps. They’re sort of like performing arithmetic on shapes instead of numbers. It’s a very logical system, but not a very intuitive one, so it took me some experimenting with transforms to become comfortable with the ways they combine together.
I gave a talk about this a couple years ago, with a Swift Playground where the audience could apply the concepts on the spot and go back over the material later. I’ve lost my notes from that talk, but the slides and Playground might still be useful. I’ve tested the Playground in Xcode 10 and it still basically works. Please drop me a line if you find an issue with a newer version of Xcode.