How do photo apps and games rotate, flip, and stretch pictures?

Every point is multiplied by a 2×2 matrix, four numbers that say where the arrows right and up end up. Rotating, mirroring, stretching, and slanting are all just different numbers. The determinant, ad − bc, tells how much areas grow, and a negative one means the picture was flipped.

The matrix0-1-0.7-0.3Column 1: where → goesColumn 2: where ↑ goesArea × 0.7determinant ad − bc = -0.7mirrored (det < 0)faint: originalshaded square: edited grid
Top-left number (a)
0
Top-right number (b)
-1
Bottom-left number (c)
-0.7
Bottom-right number (d)
-0.3
Determinant (area scale)
-0.7

Challenge: Turn the house upside down with its door still on the left.

×
×
×
Slides the top sideways, like italic text.

Play

Rotate the house 90°, then mirror it. Watch the two arrows and the four numbers.

Challenge: Turn the house upside down with its door still on the left. The box under the picture turns green when you get it.

Stuck? Pick one of the examples from the “Try an example” menu, or press “New example.”

Understand

M=[abcd],[x′y′]=M[xy]M = \begin{bmatrix} a & b \\ c & d \end{bmatrix},\quad \begin{bmatrix} x' \\ y' \end{bmatrix} = M\begin{bmatrix} x \\ y \end{bmatrix}

A matrix is four numbers. Multiply each point (x,y)(x, y) by them:

[x′y′]=[abcd][xy]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}

The columns tell the story. The first is where the arrow pointing right lands, and the second is where the arrow pointing up lands. Everything else moves along with them. The shaded square shows the grid after the edit.

The determinant ad−bcad - bc is the area scale. Below zero means the picture is mirrored.

Use

Every input has a unit menu, so you can type values in the units you already have. Results follow your units.

Show the work

  1. Stretch (a negative number mirrors)S = \begin{bmatrix} -0.7 & 0 \\ 0 & 1 \end{bmatrix}
  2. Slant: x slides over by k times yH = \begin{bmatrix} 1 & -0.3 \\ 0 & 1 \end{bmatrix}
  3. Rotate 90°R = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}
  4. Combine them: multiply the matricesM = R\,H\,S = \begin{bmatrix} 0 & -1 \\ -0.7 & -0.3 \end{bmatrix}
  5. Move a point: row times columnM\begin{bmatrix} 1.6 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ -1.12 \end{bmatrix}
  6. Area scale\det M = ad - bc = -0.7

Export

Export PDF

Rotate, stretch, slant, and mirror with the controls. The faint house is the original.

  • This is a linear map, so the corner at the origin stays put. Real editors add a shift so the picture turns around its center.

For learning and estimation. Verify with applicable codes, standards, and a qualified professional before using in design, construction, or safety-critical work.

Cheat card

R(θ)=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}
[x′y′]=[abcd][xy]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}
det⁡=ad−bc\det = ad - bc
SymbolMeaningUnit
a,ca, cwhere the arrow (1, 0) lands
b,db, dwhere the arrow (0, 1) lands
det⁡\detarea scale; negative means flipped
  • Read a matrix by its columns. Each column is where one arrow goes.
  • Doing two edits in a row means multiplying their matrices, and order matters.
  • A determinant of 0 squashes everything onto a line, and nothing can undo it.

Print this card

Where it’s used

  • Computer Science
    Games move, spin, and scale every character with matrices, many times a second.
  • Art & Design
    Photo and design apps use them for rotate, flip, and skew, and fonts use a shear to make italics.
  • Hobbies & Crafts
    Straighten a crooked photo, and you’ve used a rotation matrix.

Questions people ask

What does a 2×2 matrix do to a picture?

It moves every point to a new spot, keeping straight lines straight and the center fixed. Its two columns show where the arrows right and up end up, and the rest follows.

What does the determinant mean?

How much areas are multiplied. A determinant of 2 doubles every area, and a negative one also flips the picture over like a mirror.

Why can't a squashed picture be undone?

With a determinant of 0, whole lines of points land on the same spot. Once they're merged, no matrix can separate them again, so there's no inverse.