You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/docs/bspline-theory/page.mdx
+98-7Lines changed: 98 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
## Cubic Functions
5
5
6
6
* At its core, B-Splines are cubic functions, a function with a degree of 3.
7
-
For example, a simple linear equation: $f(x)=\ mx+b$ has a degree of 1,
7
+
For example, a simple linear equation: $f(x)= mx+b$ has a degree of 1,
8
8
because the highest power in the equation, is 1.
9
-
* A quadratic: $f(x)=\ Ax^2+Bx+C$ has a degree of 2.
9
+
* A quadratic: $f(x)= Ax^2+Bx+C$ has a degree of 2.
10
10
When increasing the degree,the base equation just gets a new coefficient and degree.
11
-
For example, a quintic equation would be $f(x) =\ Ax^5 + Bx^4 + Cx^3 + Dx^2 + Ex + F$
11
+
For example, a quintic equation would be $f(x) = Ax^5 + Bx^4 + Cx^3 + Dx^2 + Ex + F$
12
12
* Let's substitute $x$ as $t$, the time it takes between the beginning and end of a curve, usually
13
13
expressed as $t \in [0,1]$ which basically means that all curves happen on a range from 0 to 1.
14
14
* This means that any t value that is plugged into the equation, for example $t = 0.6$, will give
@@ -27,9 +27,9 @@ of $x$, it does directly correspond to the X-Axis.
27
27
* Unfortunately, simply creating a function passing through both vectors runs into the same issue.
28
28
* This is where 2D curves come in. Imagine that each $x$ and $y$ value of a function relates to another function.
29
29
This allows you to model 2 functions, one for $x$ and one for $y$.
30
-
* As a result, the functino doesn't pass through 2 points on the same $x$ value, but passes through one point on the $x$ function
30
+
* As a result, the function doesn't pass through 2 points on the same $x$ value, but passes through one point on the $x$ function
31
31
and 2 on the $y$ function.
32
-
* This can be modeled as $(x:f(t),y:g(t))$ where $f(t)$ is the x function, and $g(t)$ is the y function.
32
+
* This can be modeled as $(x:f(t),y:g(t))$ where $f(t)$ is the $x$ function, and $g(t)$ is the $y$ function.
33
33
* Imagine a coordinate plane where the $x$ axis is represented as $t$ and the $y$ axis is represented by $x$. This is the $x$ function's 'space'
34
34
* In the 'space', the coordinates from earlier could be written as $(0.2,5)$ and $(0.4,5)$, following the scheme of $(t,x)$.
35
35
* Similarly, the coordinates on the $y$ function's 'space' would be $(0.2,5)$ and $(0.4,10)$. Each function can be solved by **interpolation** (more on that later),
@@ -45,6 +45,97 @@ are connected, and the second derivatives, or the derivatives of the derivatives
45
45
* This translates to exceptionally smooth pathing without any sudden jerks, and enables efficient computing.
46
46
* B-Splines are $G_1$ continuous, meaning that the curvature is continuous. This essentially
47
47
means that the robot won't experience any acceleration jumps while traveling the path.
48
-
* Similar to Bezier Curves, B-Splines do not interpolate **ANY** control points. As a result, B-Splines do not pass through
48
+
* Similar to Bezier Curves(not exactly like), B-Splines do not interpolate **ANY** control points. As a result, B-Splines do not pass through
49
49
any of the specified control points, as only the endpoints are interpolated. However, we devised a way to get around this
50
-
using a clever mathematical concept.
50
+
using a clever mathematical concept.
51
+
* B-Splines have complete local control. This means that adjusting a control point will only
52
+
affect a small part of the curve, and not the whole thing. For example, adjusting a control point
53
+
near one of the spline's endpoints will not change anything near the other endpoint.
54
+
55
+
56
+
## B-Spline Math
57
+
58
+
How do we actually form a B Spline? Let's first talk about the matrix form of a function.
59
+
60
+
The matrix form of a function is defined as $f(t) = T*C*P$ where $T$, $C$, and $P$ are all matrices
61
+
representing the function's polynomial form. T is a matrix $\begin{bmatrix}1 & t & t^2 & t^3 \end{bmatrix}$
62
+
that represent the
63
+
$T$ value in the polynomial. The $C$ matrix, or Characteristic matrix is the thing that defines the
64
+
curve. Which looks like:
65
+
66
+
$\begin{bmatrix}
67
+
c_0 & c_1 & c_2 & c_3 \\
68
+
c_4 & c_5 & c_6 & c_7 \\
69
+
c_8 & c_9 & c_{10} & c_{11}\\
70
+
c_{12} & c_{13} & c_{14} & c_{15}\\
71
+
\end{bmatrix}$
72
+
73
+
This matrix is constant based on the type of spline you are using. For example. All cubic bezier curves will
74
+
have the same $C$ matrix, but a B-Spline will have a different one for all types of B-Splines.
75
+
Lastly, we have the $P$, the point matrix. This is expressed as:
76
+
77
+
$\begin{bmatrix}
78
+
P_0\\
79
+
P_1\\
80
+
P_2 \\
81
+
P_3 \\
82
+
\end{bmatrix}$
83
+
84
+
Now, let's put the values into the $C$ matrix and put it all together!
85
+
86
+
$f(t) =$
87
+
$\begin{bmatrix}1 & t & t^2 & t^3 \end{bmatrix}$
88
+
$\begin{bmatrix}
89
+
1 & 4 & 1 & 0 \\
90
+
-3 & 0 & 3 & 0 \\
91
+
3 & -6 & 3 & 0 \\
92
+
-1 & 3 & -3 & 1 \\
93
+
\end{bmatrix}$
94
+
$\begin{bmatrix}
95
+
P_0\\
96
+
P_1\\
97
+
P_2 \\
98
+
P_3 \\
99
+
\end{bmatrix}$
100
+
101
+
So... now that we have the matrix form, what does it do? We can use matrix multiplication to turn the
102
+
matrices into a polynomial. Let's look at the polynomial coefficient form. This is where we express
103
+
the matrix in terms of $t$, using the $P$ matrix as coefficients. First, lets express the $P$
104
+
matrix like this:
105
+
106
+
$\begin{bmatrix}
107
+
P_0 & P_1 & P_2 & P_3
108
+
\end{bmatrix}$
109
+
110
+
Now, multiply each of the $P$ values by their respective point in each row of the $C$ matrix.
111
+
112
+
113
+
$\begin{bmatrix}
114
+
1*P_0 & 4*P_1 & 1*P_2 & 0*P_3 \\
115
+
-3*P_0 & 0*P_1 & 3*P_2 & 0*P_3 \\
116
+
3*P_0 & -6*P_1 & 3*P_2 & 0*P_3 \\
117
+
-1*P_0 & 3*P_1 & -3*P_2 & 1*P_3 \\
118
+
\end{bmatrix}$
119
+
120
+
121
+
Then, we write the $T$ matrix like this:
122
+
$\begin{bmatrix}
123
+
1\\
124
+
t\\
125
+
t^2 \\
126
+
t^3 \\
127
+
\end{bmatrix}$
128
+
129
+
And finally, multiply the inside values by the corresponding rows, and add the inside of the matrix togehter,
130
+
resulting in the final polynomial coefficient form:
0 commit comments