CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Math / Trig and Waves

Rotation with Trig

Lesson 10 of 11 · 7 min · Free, no account needed

What you will learn

  • Turning by θ counterclockwise is the matrix R(θ) = [cos θ, -sin θ; sin θ, cos θ].
  • Its columns are where î and ĵ land: (cos θ, sin θ) and (-sin θ, cos θ).
  • A game turns a ship by sending every corner through the same matrix, so the shape never squashes.

Start the lesson

How the lesson goes

  1. Your game turns a spaceship by any angle, 60 times a second.

    Which four numbers do it? First: turn the ship 90°. Where does its nose land?

  2. Turn the dial and watch the whole grid turn.

    The card shows the matrix of the turn. Three goals: 90°, 180°, 30°.

  3. Drag î around the circle.

    ĵ stays a quarter turn ahead. Watch the two columns of the matrix.

  4. This is the rotation matrix.

    Turning by θ sends î to (cos θ, sin θ) and ĵ to (-sin θ, cos θ), a quarter turn ahead.

    Put them in as columns: R(θ) = [cos θ, -sin θ; sin θ, cos θ]. Any point (x, y) goes to x × column 1 + y × column 2.

  5. Build the matrix for a 270° turn.

    Fill the four boxes with 0, 1 or -1 until the ship sits on the dashed outline.

    R(270°) = [cos 270°, -sin 270°; sin 270°, cos 270°] = [0, 1; -1, 0].

  6. Turn the point (3, 1) by 90°.

    Tap the grid point where it lands.

    R(90°) = [0, -1; 1, 0], so (3, 1) goes to (0 × 3 - 1 × 1, 1 × 3 + 0 × 1) = (-1, 3).

  7. This game code squashes the ship.

    One sign is wrong. Run it, flip the wrong sign, run again.

    Row 1 of R is (cos a, -sin a), so x2 = x cos a - y sin a. With a plus, at 45° both rows are the same and the ship collapses onto a line.

  8. Game: turret.

    Three rocks. Turn the barrel until it points at the rock, then Fire.

  9. R(θ) = [cos θ, -sin θ; sin θ, cos θ].

    Draw your own ship from cells, then turn it with the matrix.

Previous lesson: Law of Cosines · Next lesson: Project: Make a Synth Note · Part of the course: Trig and Waves

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab