Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Vectors and Geometry  ›  Lesson

Vectors: Positions and Arrows

Vector 12 minA vector is a short list of numbers that can mean a position or a displacement, and subtracting, adding and scaling vectors one component at a time moves things around a game world.

Vectors: Positions and Arrows

The drone hovers above the quay and a crate waits on the dock below. To fly to it, the game needs to know where the crate is, and which way and how far to go. Both are vectors, and three simple operations on them do most of the work in any game.

From here on we look at the harbour from the side: x runs along the quay to the right, y points up, and the units are metres. The water's surface is at y=0y = 0. Everything works the same way in 3D with a third number, z.

The rule

Target minus start is the arrow from start to target.

A vector is a short list of numbers — here two, (x,y)(x, y) — and it can mean either of two things:

  • a position: the drone is at d=(2,11)\mathbf{d} = (2, 11);
  • a displacement: an arrow such as "6 m right and 8 m down", (6,−8)(6, -8). A velocity, such as (3,−4)(3, -4) m/s, is an arrow too.

Three operations do almost everything, and all three work one component at a time:

  • Subtract two positions to get the arrow between them. The crate is at c=(8,3)\mathbf{c} = (8, 3), so c−d=(8−2, 3−11)=(6,−8)\mathbf{c} - \mathbf{d} = (8 - 2,\ 3 - 11) = (6, -8).
  • Add an arrow to a position to get a new position: (2,11)+(6,−8)=(8,3)(2, 11) + (6, -8) = (8, 3).
  • Scale an arrow by a number to stretch, shrink or reverse it: 0.5×(6,−8)=(3,−4)0.5 \times (6, -8) = (3, -4), and −1×(6,−8)=(−6,8)-1 \times (6, -8) = (-6, 8) points back up at the drone.

Movement in the game loop is the same pattern with a velocity: each step, the new position is p+v Δt\mathbf{p} + \mathbf{v}\,\Delta t.

The shortcut

Say "tip minus tail": to get an arrow, take the point it ends at and subtract the point it starts from, component by component. Then check the signs against a picture. The crate is to the right of the drone (+x) and below it (−y), so the arrow must look like (+,−)(+, -). A wrong sign means you subtracted backwards.

The drone flies halfway to the crateStep 1 of 4
  1. Arrow to the crate

    Crate minus drone: (8 − 2, 3 − 11) = (6, −8).

The trap is the order of subtraction. "Drone minus crate" gives (−6,8)(-6, 8), the same arrow pointing the wrong way, and the drone flies up and away from its cargo. The sign check catches it in a second.

Drills

Answer fast — trust the rule.

quick drill

The drone is at (2, 11) and a boat at (14, 0). Which arrow points from the drone to the boat?

quick drill

A gull at (5, 6) flies with velocity (−2, 1) m/s. Where is it 3 seconds later?

quick drill

Which of these is a position rather than a displacement?

quick drill

In one second the drone's rotors carry it (0, 2) and the wind pushes it (1, 0). What is its total displacement?

Remember

  • Target minus start is the arrow from start to target.
  • Add, subtract and scale one component at a time; position + arrow = new position.
  • Check the signs against a picture: the wrong order gives the reversed arrow.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPlan the drone's flight

The drone is at (4, 10) and a boat's deck is at (10, 2). Explain how to find the arrow the drone should fly along, where the drone will be after covering a quarter of that arrow, and how you would sanity-check the signs.