FROM THE BLOG

Sketch: Easy 90 degree vector rotation

I was putting clickable name tags into Limnu the other day – they show up when multiple people are drawing, and someone draws somewhere you can’t see. A name tag appears on the border of your screen, and you can click it to zoom over to their view.

As part of figuring out where the name tag goes, I needed to rotate a vector by 90°. Normally rotating vectors involves matrix math, but there’s a really simple trick for rotating a 2D vector by 90° clockwise: just multiply the X part of the vector by -1, and then swap X and Y values.

Vectors