TExcelTAD
Home › Linear Algebra & Matrix Theory › Determinants of 2×2 and 3×3 Matrices

Determinants of 2×2 and 3×3 Matrices

The determinant of a square matrix is a single number that tells you whether the matrix is invertible and how much the matrix scales area (in 2D) or volume (in 3D). Its sign says whether the matrix keeps or flips orientation, which is exactly how a graphics card decides which side of a triangle faces the camera.

The 2×2 determinant

det⁡[abcd]=ad−bcalso written ∣abcd∣\det \begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc \qquad \text{also written } \begin{vmatrix} a & b \\ c & d \end{vmatrix}

Example: det⁡[3124]=3⋅4−1⋅2=10\det \begin{bmatrix} 3 & 1 \\ 2 & 4 \end{bmatrix} = 3 \cdot 4 - 1 \cdot 2 = 10. We met ad−bcad - bc in the inverse formula (Matrix Inverses): AA is invertible exactly when det⁡A≠0\det A \ne 0.

The 3×3 determinant

det⁡[abcdefghi]=a(ei−fh)−b(di−fg)+c(dh−eg)\det \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} = a(ei - fh) - b(di - fg) + c(dh - eg)

Each term is an entry of the first row times the 2×2 determinant left after deleting that entry's row and column, with signs +,−,++, -, +. This is the first instance of cofactor expansion (Minors and Cofactors).

Rule of Sarrus (3×3 only): copy the first two columns to the right, add the three "downhill" diagonal products and subtract the three "uphill" ones:

abcabdefdeghighdet⁡=aei+bfg+cdh−ceg−afh−bdi\begin{array}{ccc|cc} a & b & c & a & b \\ d & e & f & d & e \\ g & h & i & g & h \end{array} \qquad \det = aei + bfg + cdh - ceg - afh - bdi

Warning: Sarrus' diagonal trick does not extend to 4×4 and larger matrices. Use cofactor expansion or row reduction there.

python · try it yourself
from sympy import Matrix, symbols

def det3(M):
    a, b, c = M[0]; d, e, f = M[1]; g, h, i = M[2]
    return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g)

A = [[2, -1, 3], [0, 4, 1], [5, 2, -2]]
print("by formula:", det3(A))
print("SymPy     :", Matrix(A).det())

a, b, c, d = symbols("a b c d")
print("symbolic 2x2:", Matrix([[a, b], [c, d]]).det())
by formula: -85
SymPy     : -85
symbolic 2x2: a*d - b*c

Area, volume and orientation

2D. The columns u=[a,c]\mathbf{u} = [a, c] and v=[b,d]\mathbf{v} = [b, d] of AA span a parallelogram, the image of the unit square (Geometric Interpretation). Its area is ∣det⁡A∣\lvert \det A \rvert. So a linear map with matrix AA multiplies every area by ∣det⁡A∣\lvert \det A \rvert.

The sign records orientation: det⁡A>0\det A > 0 if turning from u\mathbf{u} to v\mathbf{v} is counter-clockwise (like e1\mathbf{e}_1 to e2\mathbf{e}_2), det⁡A<0\det A < 0 if it is clockwise, i.e. AA includes a reflection. det⁡A=0\det A = 0 means u\mathbf{u} and v\mathbf{v} are parallel and the "parallelogram" is flat.

3D. The three columns span a parallelepiped with volume ∣det⁡A∣\lvert \det A \rvert, and the sign tells whether they form a right-handed (++) or left-handed (−-) triple. In fact det⁡[u v w]=u⋅(v×w)\det[\mathbf{u}\ \mathbf{v}\ \mathbf{w}] = \mathbf{u} \cdot (\mathbf{v} \times \mathbf{w}), the scalar triple product (The Cross Product).

det⁡A\det A Meaning for the map x↦Ax\mathbf{x} \mapsto A\mathbf{x}
2 doubles areas, keeps orientation
−1 keeps areas, flips orientation (a reflection)
1 area-preserving and orientation-preserving (rotations, shears)
0 collapses the plane to a line or a point; not invertible

In software: triangle winding and back-face culling

The signed area of a triangle with vertices P0P_0, P1P_1, P2P_2 in the plane is

area=12⋅det⁡[ P1−P0P2−P0 ](the two edge vectors as columns)\text{area} = \frac{1}{2} \cdot \det [\, P_1 - P_0 \quad P_2 - P_0 \,] \qquad (\text{the two edge vectors as columns})

Positive means the vertices go round counter-clockwise, negative clockwise. Meshes list each triangle's vertices in a fixed order (counter-clockwise when seen from outside, by OpenGL's default convention). After projection to the screen, a triangle that now appears clockwise is facing away from the camera, and the GPU skips it: back-face culling, which removes about half of a closed mesh's triangles before shading. Mirroring a model (a scale with det⁡<0\det < 0) flips every winding, which is why engines must swap the culling mode for mirrored objects.

python · try it yourself
import numpy as np

def signed_area(p0, p1, p2):
    M = np.column_stack([np.subtract(p1, p0), np.subtract(p2, p0)])
    return 0.5 * float(np.linalg.det(M))

tri = [(0, 0), (4, 0), (1, 3)]
print("signed area:", round(signed_area(*tri), 6), "-> counter-clockwise (front-facing)")
print("reversed   :", round(signed_area(*tri[::-1]), 6), "-> clockwise (culled)")

mirror = np.array([[-1, 0], [0, 1]])                     # det = -1
mirrored = [tuple(mirror @ p) for p in tri]
print("after mirroring:", round(signed_area(*mirrored), 6))

shear = np.array([[1, 2], [0, 1]])                       # det = 1
sheared = [tuple(shear @ p) for p in tri]
print("after shear (det 1):", round(signed_area(*sheared), 6))
signed area: 6.0 -> counter-clockwise (front-facing)
reversed   : -6.0 -> clockwise (culled)
after mirroring: -6.0
after shear (det 1): 6.0

The same determinant test decides "is point CC left of the line ABAB?", the core predicate of convex hull algorithms, polygon triangulation and many collision tests (Ray–Triangle).

Exercises

Exercise 1: Compute

Find det⁡[5−234]\det \begin{bmatrix} 5 & -2 \\ 3 & 4 \end{bmatrix} and det⁡[120−134201]\det \begin{bmatrix} 1 & 2 & 0 \\ -1 & 3 & 4 \\ 2 & 0 & 1 \end{bmatrix}.

Answer

26 and 21.

Solution
5⋅4−(−2)⋅3=20+6=261⋅(3⋅1−4⋅0)−2⋅((−1)⋅1−4⋅2)+0⋅(…)=3−2⋅(−9)=3+18=21\begin{aligned} &5 \cdot 4 - (-2) \cdot 3 = 20 + 6 = 26 \\ &1 \cdot (3 \cdot 1 - 4 \cdot 0) - 2 \cdot ((-1) \cdot 1 - 4 \cdot 2) + 0 \cdot (\ldots) = 3 - 2 \cdot (-9) = 3 + 18 = 21 \end{aligned}
python · try it yourself
from sympy import Matrix
print(Matrix([[5, -2], [3, 4]]).det(), Matrix([[1, 2, 0], [-1, 3, 4], [2, 0, 1]]).det())
26 21

Exercise 2: When is it singular?

For which xx is det⁡[x23x−1]=0\det \begin{bmatrix} x & 2 \\ 3 & x - 1 \end{bmatrix} = 0?

Answer

x=3x = 3 or x=−2x = -2.

Solution

x(x−1)−6=x2−x−6=(x−3)(x+2)=0x(x - 1) - 6 = x^2 - x - 6 = (x - 3)(x + 2) = 0.

Exercise 3: Area of a triangle

Find the area of the triangle with vertices (1,1)(1, 1), (5,2)(5, 2), (3,6)(3, 6), and say whether this vertex order is clockwise or counter-clockwise.

Answer

Area 9; counter-clockwise.

Solution
edges: (5,2)−(1,1)=(4,1),(3,6)−(1,1)=(2,5)12⋅det⁡[4215]=12⋅(20−2)=9>0→counter-clockwise\begin{aligned} &\text{edges: } (5, 2) - (1, 1) = (4, 1), \quad (3, 6) - (1, 1) = (2, 5) \\ &\tfrac{1}{2} \cdot \det \begin{bmatrix} 4 & 2 \\ 1 & 5 \end{bmatrix} = \tfrac{1}{2} \cdot (20 - 2) = 9 > 0 \to \text{counter-clockwise} \end{aligned}

Exercise 4: Volume of a parallelepiped

Find the volume of the parallelepiped spanned by [1,0,2][1, 0, 2], [0,3,1][0, 3, 1], [2,1,0][2, 1, 0], and check it equals ∣u⋅(v×w)∣\lvert \mathbf{u} \cdot (\mathbf{v} \times \mathbf{w}) \rvert in NumPy.

Answer

Volume 13 (the determinant is −13: a left-handed triple).

Solution
det⁡=1⋅(3⋅0−1⋅1)−0⋅(…)+2⋅(0⋅1−3⋅2)=−1−12=−13→volume 13\det = 1 \cdot (3 \cdot 0 - 1 \cdot 1) - 0 \cdot (\ldots) + 2 \cdot (0 \cdot 1 - 3 \cdot 2) = -1 - 12 = -13 \to \text{volume } 13
python · try it yourself
import numpy as np
u, v, w = np.array([1, 0, 2]), np.array([0, 3, 1]), np.array([2, 1, 0])
print(round(float(np.linalg.det(np.column_stack([u, v, w]))), 6), int(u @ np.cross(v, w)))
-13.0 -13

Test yourself

What is det⁡[2713]\det \begin{bmatrix} 2 & 7 \\ 1 & 3 \end{bmatrix}?

  1. 13
  2. −13
  3. 1
  4. −1

A 2×2 matrix has determinant −3. What does it do to a shape of area 2?

  1. Maps it to area −6
  2. Maps it to area 6 and keeps orientation
  3. Maps it to area 6 and flips orientation
  4. Maps it to area 23\frac{2}{3}

Why must a game engine change the culling mode when it renders a mirrored copy of a model (scale −1 on one axis)?

  1. Mirroring doubles the triangle count
  2. The determinant of the transform is negative, so every triangle's winding flips
  3. Mirroring breaks the depth buffer
  4. It does not need to