July 20, 2019

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.

A line art yellow duckA line art yellow duck

Here’s another duck.

A line art yellow duck, rotated and scaledA line art yellow duck, rotated and scaled

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.

Keynote Slides

Playground


Previous post
Hello again, World! Look, it’s a blog. Maybe more stuff will show up here soon? Like all the posts trapped behind Medium’s nag wall right now?
Next post
Pause My microwave has a turntable that slowly rotates while the microwave is on. This is pretty common, but the turntable has a bit of a quirk. It