Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M2 Matrices and Linear Transformations / M2-T4

Linear Algebra · Theory · M2

M2-T4 — Matrices as Linear Transformations

To know what a matrix does to the whole plane, you only need to know where it sends two arrows: its columns.

  • Lesson 4 of 7
  • Module 2: Matrices and Linear Transformations
  • Matrices
  • About 9 minutes to read

Every robot has frames, sensors and units that differ by a rotation, a scaling or a flip. This lesson shows that all such changes are matrices, and that a matrix is completely determined by where it sends the basic arrows. That makes calibration, the problem of finding a matrix from a few measurements, a tractable task.

Learning objectives

After this lesson, you should be able to:

  • State the definition of a linear transformation and give a non-example.
  • Derive the matrix of a linear transformation from the images of the unit vectors.
  • Recognise scaling, rotation, reflection and shear matrices and predict their effect on a shape.
  • Explain why a translation is not linear and what that means for robot frames.

Introduction and motivation

A robot's sensor may be mounted rotated, its camera may be mirrored, its encoder units may differ from its map units. Each is a linear transformation: a rule that keeps straight lines straight and the origin fixed. The remarkable fact is that all such rules in the plane are matrices, and a matrix is pinned down by only two measurements: where the two unit arrows end up. A calibration procedure for a sensor is, at heart, measuring those two arrows.

The intuition

Imagine the plane as a sheet of graph paper. A linear transformation grabs the sheet and deforms it, subject to two rules: lines stay straight, and the origin stays put (so evenly spaced grid lines stay evenly spaced). Rotating, stretching along an axis, flipping in a mirror and shearing like a deck of cards are all examples.

Now the key idea: since every point is a mix of the two unit arrows, and mixing is preserved, you only need to know where the two unit arrows go. Write those two destinations as the columns of a matrix and you have the transformation.

Interactive figure. A two by two matrix acts on the plane. The unit square and an F-shaped outline are transformed, and two arrows show where the basis vectors land, which are the columns of the matrix. This figure needs JavaScript to be interactive.

Drag the blue handle (where the x unit arrow lands) and the gold handle (where the y unit arrow lands). The F shape shows what the whole plane does. Try the rotation by 90°: put the blue handle at (0, 1) and the gold one at (−1, 0).
Four basic transformationsThe unit square is drawn under four matrices: a stretch that doubles x, a rotation by 90 degrees, a reflection across the x axis and a shear. Each image is labelled with the matrix.scale diag(2, 1) rotate 90° reflect across x shear k = 0.5 [[2, 0], [0, 1]][[0, −1], [1, 0]][[1, 0], [0, −1]][[1, 0.5], [0, 1]]
The unit square under four basic matrices: scaling stretches an axis, rotation turns, reflection flips, shear slides rows sideways.

Geometric and physical interpretation

Geometric view. The columns (a, c) and (b, d) are the images of the arrows along x and y. The unit square becomes the parallelogram they span, and any shape is carried along. Orthogonal columns of equal length give a rotation (possibly with a flip); orthogonal columns of different lengths give a stretch plus rotation; non-orthogonal columns include shear. Physical view. A rotated sensor, a mirror-image camera and a scaled map are each a device that takes the same physical arrow and reports different numbers for it, exactly as the lesson on frames showed. The matrix is the translator.

The mathematics

T
a transformation: a rule that takes a vector x and returns a vector T(x).
e₁, e₂
the unit vectors (1, 0) and (0, 1).
M
the matrix of T, with T(x) = M x.

Definition of linearity

T(x + y) = T(x) + T(y)            T(c x) = c T(x)

What it means. Transforming a sum is the same as summing the transformed vectors, and transforming a stretched vector is the same as stretching the transformed one. These two rules keep straight lines straight and the origin fixed.

The matrix of a transformation

M = [ T(e1)  T(e2) ] = [ a  b ]
                         [ c  d ]      T(x) = M x

What it means. Column 1 is where the x unit arrow lands and column 2 is where the y unit arrow lands. Everything else is determined: this is why a calibration needs only a few measurements.

A catalogue

  • Scaling: diag(sx, sy) stretches the axes independently; a negative entry also flips that axis.
  • Rotation by θ: [[cos θ, −sin θ], [sin θ, cos θ]]: the columns are the unit arrows turned by θ.
  • Reflection across the x axis: [[1, 0], [0, −1]].
  • Shear: [[1, k], [0, 1]] slides each horizontal line sideways by k times its height.

Linear = the origin stays fixed and lines stay straight. A linear map in the plane is a 2 × 2 matrix, and its columns are the images of the unit vectors.

Step-by-step derivation: why the columns are the images of the unit vectors

Let T be linear. Any vector is x = x₁ e₁ + x₂ e₂. Then:

  1. Apply T: T(x) = T(x₁ e₁ + x₂ e₂).
  2. Use additivity: = T(x₁ e₁) + T(x₂ e₂).
  3. Use scaling: = x₁ T(e₁) + x₂ T(e₂).
  4. Write T(e₁) = (a, c) and T(e₂) = (b, d). By the column view of the last lesson, x₁ (a, c) + x₂ (b, d) is exactly [[a, b], [c, d]] x.

So every linear transformation of the plane is multiplication by the matrix whose columns are T(e₁) and T(e₂). The argument is identical in 3D with three unit vectors and a 3 × 3 matrix.

The rotation matrix. Rotate e₁ = (1, 0) by θ: it lands at (cos θ, sin θ). Rotate e₂ = (0, 1), which is e₁ turned by 90°, so it lands at the direction θ + 90°: (−sin θ, cos θ). Placing these as columns gives the rotation matrix of the table above, a result you will use in Module 7.

A non-example. A translation T(x) = x + t with t ≠ 0 sends the origin to t, but a linear map must have T(0) = T(0·0) = 0·T(0) = 0. So translations are not linear and no 2 × 2 matrix does the job.

A worked example: building and applying basic matrices

Apply four transformations to the point p = (3, 1).

  1. Scaling diag(2, 0.5): (2·3, 0.5·1) = (6, 0.5).
  2. Rotation by 90°. The columns are the unit arrows turned a quarter turn: T(e₁) = (0, 1) and T(e₂) = (−1, 0), so M = [[0, −1], [1, 0]] and M p = (−1, 3). (The length stays √10.)
  3. Reflection across the x axis: [[1, 0], [0, −1]] (3, 1) = (3, −1).
  4. Shear with k = 0.5 applied to (2, 2): [[1, 0.5], [0, 1]] (2, 2) = (2 + 0.5·2, 2) = (3, 2).
  5. Reading a matrix. For M = [[2, 0], [1, 3]] the columns are (2, 1) and (0, 3), so the x arrow lands at (2, 1) and the y arrow at (0, 3). The unit square becomes a parallelogram of area 2·3 − 0·1 = 6 (explained in the determinant lesson).

Robotics application

Sensor mounting and units. A LiDAR mounted rotated by 90° reports points through exactly the rotation above. A camera with unequal pixel sizes uses a scaling. A mirrored image (reflection) has the tell-tale sign of a negative determinant.

Calibration as finding a matrix. To calibrate the mapping from a sensor's axes to robot axes, show the sensor two known arrows and record the numbers it reports: those are the columns. In practice you use many noisy measurements and a least-squares fit (Module 5), but the underlying structure is the one in this lesson. The Systems Engineering guide on camera-LiDAR extrinsic calibration builds on the same idea.

Odometry and kinematics. The wheel-speed-to-body-velocity matrix of the last lesson is a linear transformation from a 2D wheel space to a 2D body-velocity space.

Local linearisation. A robot arm's hand position is not linear in its joint angles, but for small motions it behaves like a linear map, the Jacobian of Module 8. This is why “linear” matters even for nonlinear robots.

Engineering implications and limitations

Practical rules

  • Read columns off a calibration. If you can drive or feed a sensor along its own x and y axes, the two measured arrows are the columns of the calibration matrix.
  • Check the determinant sign. A determinant of −1 means the transformation includes a flip: a mirrored axis or a left-handed frame. A genuine rotation has determinant +1.
  • Orthogonality check. For a pure rotation or reflection the columns must be perpendicular and of length 1. Measure the dot product of the two columns: a value far from zero reveals shear or a mounting error.
  • Rotation by θ needs radians. Passing degrees to cos and sin is a classic bug that produces a plausible but wrong matrix.
  • Translations are separate. Do not try to put an offset into a 2 × 2 matrix; keep it as a separate term, or use the homogeneous form of Module 7.

Limits

Linearity is an exact property of the model, not a guarantee about reality: lens distortion, joint backlash and wheel slip are nonlinear, so a fitted matrix is valid only within the region and accuracy over which the real system behaves linearly. Check the residuals of a calibration, not just the fit.

Common misconceptions

“A linear transformation can move the origin.”

It cannot: T(0) = 0 always. Moving the origin is a translation, which is called an affine map, not a linear one.

“A matrix is a list of numbers, not something that has a geometric effect.”

Every 2 × 2 matrix deforms the whole plane in a definite way. Reading the columns as images of the unit arrows is how you see it.

“Rotations and reflections are different kinds of object with no common description.”

Both are matrices with perpendicular unit columns. The determinant tells them apart: +1 for a rotation, −1 for a reflection.

“Shear and rotation are similar because both turn things.”

A rotation keeps lengths and angles; a shear changes angles (the unit square becomes a slanted parallelogram) even though it keeps area.

Engineering takeaways

  1. A transformation is linear if T(x + y) = T(x) + T(y) and T(cx) = cT(x); it fixes the origin and keeps lines straight.
  2. The matrix of a linear transformation has the images T(e₁) and T(e₂) as its columns, and T(x) = M x.
  3. Scaling, rotation, reflection and shear are the basic matrices; the rotation matrix is [[cos θ, −sin θ], [sin θ, cos θ]].
  4. A translation is not linear: it needs the extra coordinate of Module 7.
  5. A sensor or frame calibration is, at heart, finding the columns of a matrix from measured arrows.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

A transformation sends (1, 0) to (3, 1) and (0, 1) to (−1, 2). Write its matrix and compute where it sends (2, −1).

Explanation

The images of the unit vectors are the columns: M = [[3, −1], [1, 2]]. Then M (2, −1) = 2·(3, 1) + (−1)·(−1, 2) = (6, 2) + (1, −2) = (7, 0). Row view check: row 1 · (2, −1) = 6 + 1 = 7 and row 2 · (2, −1) = 2 − 2 = 0.

Question 2

A sensor reports points as (x, y) but its true position is shifted by 0.1 m in x. Why can no 2 × 2 matrix correct this, and what is the smallest change that can?

Explanation

A 2 × 2 matrix sends the origin to the origin, but a constant shift moves the origin to (0.1, 0). A linear map cannot do that. Keep the shift as a separate addition (p′ = M p + t), or add a constant 1 coordinate and use a 3 × 3 matrix (homogeneous coordinates, Module 7), which turns the whole correction into a single matrix product.

Question 3

Two sensors both report a 2D point. Sensor A's calibration matrix has columns (0, 1) and (−1, 0); sensor B's has columns (0, 1) and (1, 0). Describe each in words and say how you could tell them apart from their determinants.

Explanation

A is a rotation by 90° counter-clockwise (the x arrow goes to y, the y arrow to −x). B swaps the axes: x goes to y and y goes to x, a reflection across the diagonal. The determinants are 0·0 − (−1)·1 = +1 for A (orientation kept) and 0·0 − 1·1 = −1 for B (orientation flipped). A negative determinant is the signature of a mirrored sensor frame.

What’s next

A single transformation is a matrix. Next you will chain transformations together and see that the matrix product is exactly their composition.

Practice this lesson

Matrix Transformation Playground

Move a robot outline with matrices: build the matrix that maps one shape onto another, and catch the order-of-composition and singular-matrix traps.

Next lesson

M2-T5 — Composition of Transformations

Combine two transformations into one matrix product and predict the effect of changing the order.

Nothing below is required to finish this lesson.