Skip to content
I.STEM Lab

Concept · Back to Basics

Vectors, coordinates and transformations: the maths behind every map and 3D scene

Points, directions, rotations and scale: the small set of ideas that sits under GIS, game engines, VR headsets and AR.

Beginner7 min read

Key takeaways

  • Every location, pixel and 3D vertex is a list of numbers, and a vector adds direction and length to it.
  • The dot product measures alignment, and the cross product gives a perpendicular direction.
  • Rotation, scale and translation can be combined into one matrix, but the order matters.
  • Most bugs come from mixed units, swapped axes and different coordinate frames.

Open a GIS, a game engine or a VR headset’s tracking system, and you find the same small set of mathematical ideas doing the work. A raster pixel is placed on the Earth by a transformation. A 3D building is placed in a scene by a transformation. A headset knows where your head is and which way it faces by a transformation. If you understand these few ideas, a great deal of GeoAI, 3D and mixed reality stops being mysterious.

This article introduces them in plain language, with small numbers you can check by hand, and finishes with the bugs they cause most often.

Points and vectors

A point is a position, such as (3, 4) on a flat map or (3, 4, 2) in 3D space with a height. A vector is a displacement: an arrow with a direction and a length. The two are closely linked. Subtract one point from another and you get the vector that leads from the first to the second.

  • From (1, 2) to (4, 6), the vector is (3, 4): three to the right and four up.
  • Its length comes from Pythagoras: the square root of 3 squared plus 4 squared, which is 5.
  • Dividing a vector by its length gives a unit vector, a pure direction of length 1. This is called normalising.

In 3D the idea is identical, with a third number, and the length uses all three squared values.

The dot product: how aligned are two directions?

Multiply the matching numbers of two vectors and add them up, and you get the dot product. For unit vectors, it equals the cosine of the angle between them. That single number tells you a lot.

  • 1 means the two directions are the same. 0 means they are at right angles. Minus 1 means opposite.
  • In graphics, the dot product of a surface’s normal and the direction of the light decides how bright the surface looks.
  • In VR and AR, it tells you whether an object is in front of or behind you, and whether a surface faces the camera.
  • In AI, the same calculation, applied to embeddings, measures how similar two meanings are.

The cross product: a direction at right angles

In 3D, the cross product of two vectors gives a third vector perpendicular to both. Its length equals the area of the parallelogram they span. It is how software finds the normal of a triangle, which decides which way a surface faces and how it is lit.

In 2D mapping, a small version of the same idea tells you the orientation of a polygon. Walk around its corners, and the sign of the result says whether you went clockwise or anticlockwise. Many GIS operations care about this, because a polygon drawn the wrong way can be treated as a hole.

Moving things around: translate, scale, rotate

Three basic operations place anything in a scene.

  • Translation slides every point by the same amount.
  • Scaling stretches or shrinks distances from a centre.
  • Rotation turns points around an axis, preserving distances and angles.

A rotation by an angle around the vertical axis uses sine and cosine. Rotating the point (1, 0, 0) by 90 degrees about that axis gives (0, 1, 0): the point swings a quarter-turn. The length stays 1, as it should, which is a useful check.

Matrices: many steps in one

A matrix is a grid of numbers that performs a transformation when it multiplies a vector. Matrices can be multiplied together to combine steps, so a whole chain of moves becomes one matrix that is applied to millions of points quickly. This is why graphics hardware is built around matrix multiplication.

A small example shows it. Take the point (0, 1, 0). Rotate it 90 degrees about the x axis and then 90 degrees about the z axis, and it ends up at (0, 0, 1). Reverse the order, and it ends up at (−1, 0, 0). Same two rotations, different result.

Homogeneous coordinates and the 4 by 4 matrix

Translation cannot be written as a simple 3 by 3 matrix. A neat trick fixes this: add a fourth number, always 1, to every point. Then rotation, scale and translation all fit in a single 4 by 4 matrix. This is why game engines, VR runtimes and mapping tools use 4 by 4 matrices everywhere. When you read about “model, view and projection matrices”, they are three of these, chained.

Coordinate frames: whose numbers are these?

The same point has different coordinates depending on whose point of view you use. A chair has coordinates in the room, in the building and on the Earth. A headset has its own frame, and so does each controller.

  • Local frame: measured from an object’s own origin, for example a doorway from the door.
  • World frame: shared by the whole scene or map.
  • Camera or head frame: centred on the viewer, with the viewing direction as one axis.

Much of mixed reality is the careful conversion between frames: where is the controller relative to the room, where is the room relative to the building and where is the building on the Earth?

Orientation and a word on quaternions

A headset reports position (three numbers) and orientation. Orientation can be given as three angles, but angles have a flaw called gimbal lock, where two axes line up and a degree of freedom is lost. Quaternions, a set of four numbers, avoid this and blend smoothly between orientations, so tracking systems prefer them. You rarely need to compute with them by hand, but you should know why they exist when you see them in a data format.

The same ideas in GIS

A geotransform, the small set of numbers stored with every raster, is a transformation. It converts a pixel’s column and row into map coordinates. If the top-left corner is at x 500,000 and y 3,100,000 metres, with 10 metre pixels, then the centre of the pixel at column 250 and row 100 sits at x 502,505 and y 3,098,995. Notice that y goes down as row goes up, because image rows count downwards while map northings count upwards. That one difference causes countless flipped images.

The bugs these ideas cause

  • Mixed units: millimetres versus metres, or degrees versus radians. Trigonometric functions expect radians.
  • Swapped axes: latitude then longitude versus x then y, which is longitude then latitude.
  • Handedness: some systems are right-handed and others left-handed, so a model can appear mirrored.
  • Row and column order: arrays are indexed by row first, but maps by x first.
  • Forgetting the order of transformations, so objects appear in the wrong place.

Frequently asked questions

Why do graphics and VR use matrices instead of simple formulas?
Because matrices combine many steps into one, and graphics hardware is designed to apply them to millions of points in parallel.
Do I need to calculate this by hand?
Rarely. Libraries do it for you. But doing a few small examples by hand gives you the intuition to spot a wrong result.
What is the difference between a point and a vector?
A point is a position. A vector is a displacement, with direction and length. Software often stores both as lists of numbers, which is why they get confused.
How can I test a transformation?
Apply it to a point whose result you know, check that lengths and angles are preserved when they should be, and reverse it to see whether you return to the start.

Positions, directions and transformations are the grammar of spatial computing. Learn them once, and every map, scene and headset you meet will make more sense.

Share

Join the conversation

Reactions & comments

Comments are opening soon.

In the meantime, tell us what you think by email at info.istem.lab@gmail.com.

Start a project

Need this built for your organization?

If you would rather have a working system than a tutorial, tell us your goal and we will scope it with you.