There's a graphics trick that used to be widely known that has now probably almost vanished from the graphics consciousness - you can do rotation

cohost! - "Rotation with three shears"

submited by
Style Pass
2023-01-23 06:00:07

There's a graphics trick that used to be widely known that has now probably almost vanished from the graphics consciousness - you can do rotations by applying three shears in a row. This should surprise you! It surprised me. And it re-surprises me every time I remember it.

Shears are very simple graphics operations to do - you just render the sprite, but shifting the lines or columns a bit each time. But rotations are gnarly things that involve lots of maths and interpolation and so on. So how could you possibly construct one from the other?

The derivation is relatively simple, but I won't do it here because there's a perfectly good explanation over here: https://www.ocf.berkeley.edu/~fricke/projects/israel/paeth/rotation_by_shearing.html

This works for all angles -90 degrees to +90 degrees, which is fantastic! Beyond that you just need to apply an X and Y flip first (i.e. a rotation by 180), which can usually be done as part of the first shear.

Leave a Comment