1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-06 16:56:57 +02:00
Files
BezierInfo-2/components/sections/matrix/content.en-GB.md
2020-01-21 08:55:57 +01:00

4.4 KiB

Bézier curvatures as matrix operations

We can also represent Bézier curves as matrix operations, by expressing the Bézier formula as a polynomial basis function and a coefficients matrix, and the actual coordinates as a matrix. Let's look at what this means for the cubic curve, using P... to refer to coordinate values "in one or more dimensions":

[ B(t) = P_1 \cdot (1-t)^3 + P_2 \cdot 3 \cdot (1-t)^2 \cdot t + P_3 \cdot 3 \cdot (1-t) \cdot t^2 + P_4 \cdot t^3 ]

Disregarding our actual coordinates for a moment, we have:

[ B(t) = (1-t)^3 + 3 \cdot (1-t)^2 \cdot t + 3 \cdot (1-t) \cdot t^2 + t^3 ]

We can write this as a sum of four expressions:

[ \begin{matrix} ... & = & (1-t)^3 \ & + & 3 \cdot (1-t)^2 \cdot t \ & + & 3 \cdot (1-t) \cdot t^2 \ & + & t^3 \ \end{matrix} ]

And we can expand these expressions:

[ \begin{matrix} ... & = & (1-t) \cdot (1-t) \cdot (1-t) & = & -t^3 + 3 \cdot t^2 - 3 \cdot t + 1 \ & + & 3 \cdot (1-t) \cdot (1-t) \cdot t & = & 3 \cdot t^3 - 6 \cdot t^2 + 3 \cdot t \ & + & 3 \cdot (1-t) \cdot t \cdot t & = & -3 \cdot t^3 + 3 \cdot t^2 \ & + & t \cdot t \cdot t & = & t^3 \ \end{matrix} ]

Furthermore, we can make all the 1 and 0 factors explicit:

[ \begin{matrix} ... & = & -1 \cdot t^3 + 3 \cdot t^2 - 3 \cdot t + 1 \ & + & +3 \cdot t^3 - 6 \cdot t^2 + 3 \cdot t + 0 \ & + & -3 \cdot t^3 + 3 \cdot t^2 + 0 \cdot t + 0 \ & + & +1 \cdot t^3 + 0 \cdot t^2 + 0 \cdot t + 0 \ \end{matrix} ]

And that, we can view as a series of four matrix operations:

[ \begin{bmatrix}t^3 & t^2 & t & 1\end{bmatrix} \cdot \begin{bmatrix}-1 \ 3 \ -3 \ 1\end{bmatrix}

  • \begin{bmatrix}t^3 & t^2 & t & 1\end{bmatrix} \cdot \begin{bmatrix}3 \ -6 \ 3 \ 0\end{bmatrix}
  • \begin{bmatrix}t^3 & t^2 & t & 1\end{bmatrix} \cdot \begin{bmatrix}-3 \ 3 \ 0 \ 0\end{bmatrix}
  • \begin{bmatrix}t^3 & t^2 & t & 1\end{bmatrix} \cdot \begin{bmatrix}1 \ 0 \ 0 \ 0\end{bmatrix} ]

If we compact this into a single matrix operation, we get:

[ \begin{bmatrix}t^3 & t^2 & t & 1\end{bmatrix} \cdot \begin{bmatrix} -1 & 3 & -3 & 1 \ 3 & -6 & 3 & 0 \ -3 & 3 & 0 & 0 \ 1 & 0 & 0 & 0 \end{bmatrix} ]

This kind of polynomial basis representation is generally written with the bases in increasing order, which means we need to flip our t matrix horizontally, and our big "mixing" matrix upside down:

[ \begin{bmatrix}1 & t & t^2 & t^3\end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & 0 \ -3 & 3 & 0 & 0 \ 3 & -6 & 3 & 0 \ -1 & 3 & -3 & 1 \end{bmatrix} ]

And then finally, we can add in our original coordinates as a single third matrix:

[ B(t) = \begin{bmatrix} 1 & t & t^2 & t^3 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & 0 \ -3 & 3 & 0 & 0 \ 3 & -6 & 3 & 0 \ -1 & 3 & -3 & 1 \end{bmatrix} \cdot \begin{bmatrix} P_1 \ P_2 \ P_3 \ P_4 \end{bmatrix} ]

We can perform the same trick for the quadratic curve, in which case we end up with:

[ B(t) = \begin{bmatrix} 1 & t & t^2 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 \ -2 & 2 & 0 \ 1 & -2 & 1 \end{bmatrix} \cdot \begin{bmatrix} P_1 \ P_2 \ P_3 \end{bmatrix} ]

If we plug in a t value, and then multiply the matrices, we will get exactly the same values as when we evaluate the original polynomial function, or as when we evaluate the curve using progressive linear interpolation.

So: why would we bother with matrices? Matrix representations allow us to discover things about functions that would otherwise be hard to tell. It turns out that the curves form triangular matrices, and they have a determinant equal to the product of the actual coordinates we use for our curve. It's also invertible, which means there's a ton of properties that are all satisfied. Of course, the main question is "why is this useful to us now?", and the answer to that is that it's not immediately useful, but you'll be seeing some instances where certain curve properties can be either computed via function manipulation, or via clever use of matrices, and sometimes the matrix approach can be (drastically) faster.

So for now, just remember that we can represent curves this way, and let's move on.