Basis and Dimension
A basis is a list of vectors from which every vector of the space can be built in exactly one way. The number of vectors in a basis, the dimension, is the same for every basis, and it is the true "size" of a space. Choosing a good basis is a design decision: the Bernstein basis of polynomials, for example, is what makes Bézier curves work.
Definitions
A list in a vector space is a basis of if it is
- linearly independent, and
- spans (Linear Combinations, Span and Linear Independence).
Then every has exactly one expression . Spanning gives at least one; independence gives at most one, since two different expressions would subtract to a nontrivial combination equal to . The numbers are the coordinates of in this basis, written .
Theorem. If has a basis with vectors, every basis of has vectors. This is the dimension, . (The key step, as in the lesson Basis and Dimension: in a space spanned by vectors, any vectors are dependent.)
Two shortcuts follow. In a space of dimension :
- any independent vectors already span, so they are a basis;
- any vectors that span are already independent, so they are a basis.
Dimensions of familiar spaces
| Space | Standard basis | Dimension |
|---|---|---|
| (degree ) | ||
| the matrices with a single 1 | ||
| symmetric matrices | and () | |
| solutions of | 2 | |
| (with vectors in total) | ||
| all polynomials | infinite | |
| no finite basis | infinite |
A space with no finite basis is infinite-dimensional. In such a space, there are arbitrarily long independent lists ( for any ).
Coordinates change with the basis
The coordinates of a vector depend on the basis. In with the basis , the polynomial has coordinates . In the basis it has coordinates , since . Neither is more correct. A basis is a coordinate system, and you pick the one that makes the job easy.
The Bernstein basis and Bézier curves
For a fixed degree , the Bernstein polynomials are
There are of them in the -dimensional space , so they form a basis as soon as they are independent. Their coefficient columns in the basis form a triangular matrix with nonzero diagonal:
from sympy import symbols, binomial, Poly, Matrix, expand
t = symbols("t")
n = 3
B = [binomial(n, i) * t**i * (1 - t)**(n - i) for i in range(n + 1)]
M = Matrix([[Poly(b, t).coeff_monomial(t**k) for b in B] for k in range(n + 1)])
print("columns = Bernstein polynomials in the basis 1, t, t^2, t^3:")
for row in M.tolist():
print(" ", row)
print("det =", M.det(), "-> a basis of P3")
print("sum of the basis:", expand(sum(B)))columns = Bernstein polynomials in the basis 1, t, t^2, t^3:
[1, 0, 0, 0]
[-3, 3, 0, 0]
[3, -6, 3, 0]
[-1, 3, -3, 1]
det = 9 -> a basis of P3
sum of the basis: 1
The determinant proves independence. The basis also adds up to 1 (because ), and every is on . These two facts are what graphics needs.
A Bézier curve with control points is the curve whose Bernstein coordinates are those points:
Since the weights are non-negative and add up to 1, every is a weighted average of the control points: the curve stays inside their convex hull, starts at (only is nonzero at ) and ends at . Moving one control point changes one coordinate, which bends the curve smoothly (Bézier Curves).
import numpy as np
import matplotlib.pyplot as plt
from math import comb
P = np.array([[0.0, 0.0], [1.0, 2.0], [3.0, 3.0], [4.0, 0.0]])
n = len(P) - 1
ts = np.linspace(0, 1, 101)
weights = np.array([[comb(n, i) * t**i * (1 - t)**(n - i) for i in range(n + 1)] for t in ts])
curve = weights @ P # each row: Bernstein weights times control points
plt.figure(figsize=(6, 4))
plt.plot(P[:, 0], P[:, 1], "o--", color="0.6", label="control polygon")
plt.plot(curve[:, 0], curve[:, 1], lw=2, label="cubic Bézier")
plt.legend(); plt.gca().set_aspect("equal"); plt.grid(alpha=0.3)
print("B(0) =", curve[0].tolist(), " B(1) =", curve[-1].tolist(), " B(0.5) =", curve[50].tolist())
print("weights at t = 0.5:", weights[50].tolist())B(0) = [0.0, 0.0] B(1) = [4.0, 0.0] B(0.5) = [2.0, 1.875]
weights at t = 0.5: [0.125, 0.375, 0.375, 0.125]
At the weights are , so .
In software
- Fonts and vector graphics: TrueType glyphs use quadratic Bézier curves, PostScript, CFF fonts and SVG paths use cubic ones; all are polynomials stored by their Bernstein coordinates.
- Animation and CSS:
cubic-bezier(x1, y1, x2, y2)easing curves are cubic Béziers with and . - Compression and ML: storing a signal in a better basis (Fourier, wavelets, principal components) concentrates it in few coordinates (The Singular Value Decomposition).
- Numerics: the monomial basis is badly conditioned for high degree; numerical code prefers Chebyshev or Bernstein bases for the same space.
Exercises
Exercise 1: Upper triangular matrices
What is the dimension of the space of upper triangular matrices? Give a basis.
Answer
Dimension 3; basis , , .
Solution
Every upper triangular matrix is (spanning), and this is the zero matrix only if (independent).
Exercise 2: Degree-1 Bernstein coordinates
Find the coordinates of in the Bernstein basis , .
Answer
.
Solution
Shortcut: for degree 1 the coordinates are the values and . That is why a straight segment is drawn from its two endpoints.
Exercise 3: and in Bernstein form
Using the degree-2 basis , , , find the coordinates of , and .
Answer
; ; .
Solution
Exercise 4: Convert in code
Find the degree-2 Bernstein coordinates of , by hand and with SymPy.
Answer
.
Solution
From Exercise 3, add the coordinates of , and : . Check: and .
from sympy import symbols, solve, expand, Poly
t, a, b, c = symbols("t a b c")
p = 1 + t + t**2
combo = a * (1 - t)**2 + b * 2 * t * (1 - t) + c * t**2
eqs = Poly(expand(combo - p), t).all_coeffs() # every coefficient must vanish
print(solve(eqs, [a, b, c])){a: 1, b: 3/2, c: 3}
Test yourself
What is the dimension of , the polynomials of degree at most 4?
- 4
- 5
- 16
- Infinite
In a 3-dimensional space, three linearly independent vectors…
- might not span the space
- always form a basis
- must include the zero vector
- are always orthogonal
Why does a Bézier curve stay inside the convex hull of its control points?
- Because the Bernstein polynomials are orthogonal
- Because on the Bernstein weights are non-negative and add up to 1
- Because the curve is a straight line
- Because the control points are a basis