Skip to content

Lesson: Stepping up to 3D

For four lessons you have been working on a flat sheet: two basis vectors, 2x2 matrices, the unit square. Now step off the page. Add depth, the third direction, and work in the space you actually live in.

Here is the reassuring part, and it is the whole point of this lesson. Almost nothing changes. The definitions, the basis-vector trick, the matrix-as-columns idea, matrix multiplication as composition, all of it carries over to 3D untouched. You add one more basis vector, one more column, one more number per vector, and the machinery runs exactly as before. If you understood the last three lessons, you already understand most of this one.

A transformation of 3D space is linear under the same two requirements as before: the origin stays fixed, and grid lines stay straight, parallel, and evenly spaced, now in three directions instead of two. Picture a 3D grid of little cubes. A linear transformation can stretch it, rotate it, shear it, or flip it, but it can never curve the lines or space them unevenly. Same rules, more room.

In 2D you had two basis vectors. In 3D you get a third. The standard basis is:

i-hat = [1, 0, 0] j-hat = [0, 1, 0] k-hat = [0, 0, 1]

i-hat points one unit along the x-axis, j-hat one unit along the y-axis, and the new arrival k-hat one unit along the z-axis, straight out of the old flat plane toward you. Every 3D vector is a combination of these three: the vector 3, 4, 5 is just 3 times i-hat plus 4 times j-hat plus 5 times k-hat, three steps along the x-axis, four along the y-axis, five along the z-axis.

A 3D linear transformation is fully determined by where it sends i-hat, j-hat, and k-hat. Same logic as 2D: every vector is a combination of the basis vectors, the transformation preserves the combination, so knowing the three landing spots tells you where every vector goes.

L(v) = x · L(i-hat) + y · L(j-hat) + z · L(k-hat)

A 3x3 matrix records those three landing spots as columns, and each column is now a 3D vector with three entries:

[ a b c ] first column [a, d, g] = L(i-hat)
[ d e f ] second column [b, e, h] = L(j-hat)
[ g h i ] third column [c, f, i] = L(k-hat)

The matrix-vector product extends in the obvious way. For a general 3D vector,

M · v = x · (first column) + y · (second column) + z · (third column)

Three terms instead of two. That is the only change. And matrix multiplication still means composition: each column of the product AB is A applied to the corresponding column of B, exactly as before, just with 3-vector columns.

The 3D standard basis i-hat, j-hat, k-hat decompose [3, 4, 5] as 3 i-hat plus 4 j-hat plus 5 k-hat A three-dimensional coordinate scene in axonometric projection. Three short bold unit arrows at the origin: a teal i-hat along the x axis, an amber j-hat along the y axis, and a sky-blue k-hat along the z axis. A dashed path traces the decomposition: three steps along x, then four steps along y, then five steps upward along z, arriving at [3, 4, 5]. A bold purple arrow runs from the origin straight to the same point, labeled "[3, 4, 5] = 3 i-hat plus 4 j-hat plus 5 k-hat". x y z î ĵ [3, 4, 5] decomposition into basis: [3, 4, 5] = 3 î + 4 ĵ + 5 three steps right, four back, five up
The 3D standard basis adds one direction to the 2D one: k-hat points up along z. Any 3D vector is just so many î plus so many ĵ plus so many k̂. The triple [3, 4, 5] is the recipe for the walk: three right, four back, five up.

Worked example: rotation around the z-axis

Section titled “Worked example: rotation around the z-axis”

A quarter turn in the plane was one matrix. In 3D you have to say which axis you turn around, because “rotation” is no longer a single idea. Start with a quarter turn around the z-axis, the one pointing out of the old plane.

Looking down the z-axis, this is just the familiar 2D rotation happening in the x-y plane, while z is left alone. So i-hat swings to 0, 1, 0, j-hat swings to negative-1, 0, 0, and k-hat stays exactly where it is at 0, 0, 1, because points on the z-axis do not move when you spin around it. The matrix:

[ 0 -1 0 ]
[ 1 0 0 ]
[ 0 0 1 ]

Apply it to the vector 3, 4, 5:

3 · [0, 1, 0] + 4 · [-1, 0, 0] + 5 · [0, 0, 1] = [0, 3, 0] + [-4, 0, 0] + [0, 0, 5] = [-4, 3, 5]

The x-axis and y-axis parts rotated just like the old 2D example (the vector 3, 4 became negative-4, 3), and the height 5 rode along untouched. The third column being a plain 0, 0, 1 is the matrix telling you “the z-axis is left alone.”

A 90 degree rotation about z: k-hat stays put, i-hat and j-hat sweep around Two side-by-side panels showing a unit cube before and after a 90 degree counter-clockwise rotation about the z axis. In the left panel, the cube sits at the origin with i-hat pointing along positive x in teal, j-hat along positive y in amber, and k-hat pointing up in sky blue. A circular arrow between the panels indicates the rotation. In the right panel, the cube has rotated about the vertical axis: i-hat now lies along positive y, j-hat now lies along negative x, and k-hat is unchanged because the rotation is around it. BEFORE î ĵ AFTER (90° about z) î' ĵ' k̂' = k̂ Rz(90°) k̂ fixed
Rotation about z is the easiest 3D rotation: only the floor-level plane rotates, and the height direction k-hat is left alone. So the new k-hat is the same as the old; the new i-hat lands where j-hat used to be, and the new j-hat lands along negative x.

Worked example: rotation around the y-axis

Section titled “Worked example: rotation around the y-axis”

Change the axis and you get a genuinely different transformation. Rotate a quarter turn around the y-axis instead. Now j-hat is the one left alone, and the action happens in the x-z plane. Send i-hat to 0, 0, negative-1 (the x direction tips down toward negative z), keep j-hat at 0, 1, 0, and send k-hat to 1, 0, 0 (the z direction swings toward positive x). The matrix:

[ 0 0 1 ]
[ 0 1 0 ]
[-1 0 0 ]

Apply it to the vector 3, 4, 5:

3 · [0, 0, -1] + 4 · [0, 1, 0] + 5 · [1, 0, 0] = [0, 0, -3] + [0, 4, 0] + [5, 0, 0] = [5, 4, -3]

This time the height 4 along y was the part left untouched, while x and z traded places with a sign flip. Same idea as the z-axis turn, different axis, different fixed direction. In 3D you always have to name the axis.

A diagonal matrix scales each axis independently. Take

[ 2 0 0 ]
[ 0 3 0 ]
[ 0 0 0.5 ]

The columns say i-hat doubles to 2, 0, 0, j-hat triples to 0, 3, 0, and k-hat shrinks to 0, 0, 0.5. Apply to the vector 3, 4, 5:

3 · [2, 0, 0] + 4 · [0, 3, 0] + 5 · [0, 0, 0.5] = [6, 12, 2.5]

Each coordinate just scaled by its own factor: the x-direction doubled, the y-direction tripled, the z-direction halved. A diagonal matrix is the simplest 3D transformation to read, because each axis minds its own business.

Sketching what a 3D matrix does to the unit cube

Section titled “Sketching what a 3D matrix does to the unit cube”

This is the capability to carry away, and it is the direct lift of last lessons’ unit-square sketch. In 2D you plotted the two columns and drew the parallelogram they spanned. In 3D you plot the three columns and draw the parallelepiped, a slanted box, that they span.

The unit cube sits with one corner at the origin and edges of length one along each axis (its eight corners are every combination of 0 and 1 in the three coordinates). To see what a 3x3 matrix does, plot its three columns as arrows from the origin: those are the three edges of the transformed box. The cube becomes the parallelepiped hanging off those three edges, and that shape tells you the whole story of the transformation, stretched, rotated, sheared, or flattened.

The unit cube becomes a slanted parallelepiped under a 3D linear transformation Two side-by-side panels. The left panel shows the unit cube at the origin with i-hat, j-hat, k-hat as the three short bold arrows along the cube's three edges from the origin. The right panel shows the parallelepiped that the cube becomes under a linear transformation L. The parallelepiped's three edges from the origin are the three columns of the matrix L: teal L of i-hat, amber L of j-hat, and sky-blue L of k-hat. The matrix and the parallelepiped carry the same information in two notations. BEFORE: unit cube î ĵ AFTER L: parallelepiped L(î) L(ĵ) L(k̂) columns of L = [ L(î) | L(ĵ) | L(k̂) ]
In 3D, the unit cube takes the place of the unit square. Under any 3D linear transformation, the cube becomes a slanted parallelepiped, and its three edges from the origin are the three columns of the 3x3 matrix. Same story as 2D, one dimension up.

Work one through. For the scaling matrix above, the three columns are 2, 0, 0, then 0, 3, 0, then 0, 0, 0.5, all still pointing along the axes. The unit cube becomes a rectangular box two units wide, three tall, half a unit deep: no slant, just stretched and squashed along each direction. For the z-axis rotation, the three columns stay unit length and perpendicular, so the cube stays a cube and only spins a quarter turn. You read the box straight off the columns, without testing a single interior point.

If the three columns get nearly coplanar, all lying close to one flat sheet, the parallelepiped squashes nearly flat, the same warning sign as the 2D case: the transformation is collapsing 3D space down toward a plane or a line.

Three dimensions is the last stop where you can actually picture what is happening. The models you care about work in hundreds or thousands of dimensions, far past anything you can draw. This lesson is the bridge to that, and the message is simple: the jump from 2D to 3D is the same jump that goes to 300 dimensions or more. Nothing new appears. You add basis vectors, the columns get taller, the products get more terms, and every rule holds exactly.

That is worth holding onto when a model has a “768-dimensional embedding space.” It means 768 basis directions, vectors with 768 entries, and matrices with 768 columns, behaving by the rules you just used on the vector 3, 4, 5. You cannot sketch the cube anymore, but you do not need to. As the first lesson put it, high-dimensional means long list, not magic. 3D is just the last list you can see.

Saying “rotation” without naming the axis. In 2D there was one way to rotate. In 3D you must say which axis you turn around; rotation about the z-axis, the y-axis, and the x-axis are three different transformations with three different matrices.

Expecting new rules in 3D. There are none. If a 2D rule felt solid, the 3D version is the same rule with one more basis vector. Anyone waiting for 3D to introduce a twist is waiting for nothing.

Reading a 3x3 matrix by rows. The meaning is still in the columns: three destination vectors, one each for i-hat, j-hat, k-hat. A 3x3 matrix is three 3D vectors standing side by side.

Thinking the cube must stay a cube. Only rigid rotations keep it a cube. Stretches make it a box, shears make it a slanted parallelepiped, and a flattening transformation crushes it toward a plane. The shape of the transformed cube is the readout.

  • 3D linear transformations follow every rule from 2D, with one more dimension. Origin fixed, grid lines straight and even, now in three directions. There is no new conceptual machinery to learn here.
  • A 3x3 matrix is where i-hat, j-hat, and k-hat land, written as three columns, and the product M times the vector equals the x-coordinate times column one plus the y-coordinate times column two plus the z-coordinate times column three. To sketch its effect, plot the three columns and draw the parallelepiped they span out of the unit cube.
  • The leap to 3D is the same leap to any dimension. Add basis vectors, lengthen the columns, add terms to the product. Everything you learned on the plane runs unchanged in the hundreds of dimensions a real model uses.

3D adds a dimension, not a difficulty. The same record of where the basis lands still moves all of space, there is just more space to move. Next we ask a sharper question about any transformation: by how much does it stretch or squash the space it acts on? That number is the determinant.