Skip to content

Commit bd12afe

Browse files
authored
Merge pull request #89 from awesumdude42/main
ok so... i added a bunch math to the B-Spline theory file! i explained how matrix form works!
2 parents 06b58e1 + b41e535 commit bd12afe

2 files changed

Lines changed: 101 additions & 10 deletions

File tree

app/docs/bspline-theory/page.mdx

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
## Cubic Functions
55

66
* 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,
88
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.
1010
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$
1212
* Let's substitute $x$ as $t$, the time it takes between the beginning and end of a curve, usually
1313
expressed as $t \in [0,1]$ which basically means that all curves happen on a range from 0 to 1.
1414
* 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.
2727
* Unfortunately, simply creating a function passing through both vectors runs into the same issue.
2828
* This is where 2D curves come in. Imagine that each $x$ and $y$ value of a function relates to another function.
2929
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
3131
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.
3333
* 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'
3434
* In the 'space', the coordinates from earlier could be written as $(0.2,5)$ and $(0.4,5)$, following the scheme of $(t,x)$.
3535
* 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
4545
* This translates to exceptionally smooth pathing without any sudden jerks, and enables efficient computing.
4646
* B-Splines are $G_1$ continuous, meaning that the curvature is continuous. This essentially
4747
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
4949
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:
131+
132+
$f(t)=$
133+
134+
$(P_0 + 4P_1 + P_2)$        $+$
135+
136+
$t(-3P_0 + 3P_2)$       $+$
137+
138+
$t^2(3P_0 - 6P_1 + 3P_2 )$        $+$
139+
140+
$t^3(-P_0 + 3P_1 + -3P_2 + P_3)$
141+

next.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import nextra from 'nextra'
33
// Set up Nextra with its configuration
44
const withNextra = nextra({
55
// ... Add Nextra-specific options here
6-
latex:{
7-
renderer: 'mathjax'
8-
}
6+
latex:{
7+
renderer: 'mathjax'
8+
}
99
})
1010

1111
const nextConfig = {

0 commit comments

Comments
 (0)