<p>If you want to determine those matrices you have to use the knot vector <span class="math-container">$[0, 0, 0, 0, 4, 5, 6,...]$</span> and write out the expressions using the Cox-DeBoor algorithm. I believe you will need to compute the functions on two knot spans and therefore obtain two different matrices.</p>
<p>However, you can also use a little trick here by constructing a ghost point. If You construct a point <span class="math-container">$P_{g} = (2P_0 - P_1)$</span> and then apply <span class="math-container">$M_2$</span> to <span class="math-container">$\begin{bmatrix} 
           P_{g} \\
           P_0 \\
           P_1 \\
           P_2
         \end{bmatrix}$</span> you will end up with the following situation:
<a href="https://i.sstatic.net/m9l1L.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/m9l1L.png" alt="enter image description here" /></a>
Here curve <span class="math-container">$a$</span> is constructed using control points <span class="math-container">$[P_{g}, P_0, P_1, P_2]$</span> and curve <span class="math-container">$b$</span> with <span class="math-container">$[P_0, P_1, P_2, P_3]$</span>. Naturally, the same can be done at the end of the curve by creating a ghost point <span class="math-container">$P_g = 2P_n - P_{n-1}$</span>. If you need the matrix you will have to substitute <span class="math-container">$(2P_0 - P_1)$</span> for <span class="math-container">$P_g$</span> and find out which functions act on <span class="math-container">$P_0$</span> and <span class="math-container">$P_1$</span> by writing out the equations and collecting the terms.</p>

CC BY-SA 4.0
2023-07-22T17:41:16.907Z
Great, adding an extra point does the trick, thank you! Next step will be for me to understand why we can't apply the same logic than for a quadratic bezier and why we need to introduce that knot vector, but for the time being, adding a point at the beginning works! Thank you so much =]
fruity
CC BY-SA 4.0
2023-06-15T07:39:39.860Z
2023-07-25T07:14:15.680Z
2023-07-25T07:14:15.680Z
Reynolds
<p>I'm trying to find the matrix form for the equation of a cubic b-spline. More specifically, the &quot;middle&quot; part, S_i(t), is pretty straightforward and available everywhere:</p>
<pre><code>M2 = [
  [-1,  3, -3,  1],
  [ 3, -6,  0,  4],
  [-3,  3,  3,  1],
  [ 1,  0,  0,  0]]) * 1/6.
</code></pre>
<p>But I struggle finding S_0(t) and S_n-3(t), that is, the first and last segment, that respectively start on the first control point and ends on the last control point</p>
<p>To help explain what I'm looking for, here is exactly it for a quadratic B-Spline (taken from <a href="https://www.youtube.com/watch?v=qhQrRCJ-mVg" rel="nofollow noreferrer">here</a>):</p>
<pre><code>M1 = [
  [2, -4, 2],
  [-3, 4, 0],
  [1, 0, 0]]) * 1/2.
M2 = [
  [1, -2, 1],
  [-2, 2, 1], 
  [1, 0, 0]]) * 1/2.
M3 = [
  [1, -2, 1],
  [-3, 2, 1], 
  [2, 0, 0]]) * 1/2.
</code></pre>
<p>With those 3 matrices, if we work on <code>P0, P1, P2</code>, we use <code>M1</code>. If we work on <code>Pn-2, Pn-1, Pn</code>, we use <code>M3</code>. For everything else, <code>M2</code>.</p>
<p>To summarize, I'm looking for M1 and M3, but for a cubic B-spline, not for a quadratic like just above.</p>
<p>Here is an image, to understand better:
<a href="https://i.sstatic.net/2LSpa.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2LSpa.png" alt="" /></a></p>
<ul>
<li><em>Green crosses: the control points of my cubic spline</em></li>
<li><em>Red curve: desired result</em></li>
<li><em>Yellow crosses: my current result. The middle part works, not the start/end (currently, this is just bezier)</em></li>
</ul>
<p>Any help will be greatly appreciated, thank you!</p>

<matrix><vector-graphics><nurbs><spline>
Matrix form of an open uniform cubic b-spline
fruity
# Matrix form of an open uniform cubic b-spline

(Asked by: username_0 on 2023-06-10)

I'm trying to find the matrix form for the equation of a cubic b-spline. More specifically, the "middle" part, S\_i(t), is pretty straightforward and available everywhere:

```
M2 = [
  [-1,  3, -3,  1],
  [ 3, -6,  0,  4],
  [-3,  3,  3,  1],
  [ 1,  0,  0,  0]]) * 1/6.

```

But I struggle finding S\_0(t) and S\_n-3(t), that is, the first and last segment, that respectively start on the first control point and ends on the last control point

To help explain what I'm looking for, here is exactly it for a quadratic B-Spline (taken from [here](https://www.youtube.com/watch?v=qhQrRCJ-mVg)):

```
M1 = [
  [2, -4, 2],
  [-3, 4, 0],
  [1, 0, 0]]) * 1/2.
M2 = [
  [1, -2, 1],
  [-2, 2, 1], 
  [1, 0, 0]]) * 1/2.
M3 = [
  [1, -2, 1],
  [-3, 2, 1], 
  [2, 0, 0]]) * 1/2.

```

With those 3 matrices, if we work on `P0, P1, P2`, we use `M1`. If we work on `Pn-2, Pn-1, Pn`, we use `M3`. For everything else, `M2`.

To summarize, I'm looking for M1 and M3, but for a cubic B-spline, not for a quadratic like just above.

Here is an image, to understand better:
[![](https://i.sstatic.net/2LSpa.png)](https://i.sstatic.net/2LSpa.png)

* *Green crosses: the control points of my cubic spline*
* *Red curve: desired result*
* *Yellow crosses: my current result. The middle part works, not the start/end (currently, this is just bezier)*

Any help will be greatly appreciated, thank you!

**Tags:** matrix, vector-graphics, nurbs, spline


---

## 1 answers

### Answer by username_1 on 2023-06-15. Score: 1

If you want to determine those matrices you have to use the knot vector $[0, 0, 0, 0, 4, 5, 6,...]$ and write out the expressions using the Cox-DeBoor algorithm. I believe you will need to compute the functions on two knot spans and therefore obtain two different matrices.

However, you can also use a little trick here by constructing a ghost point. If You construct a point $P\_{g} = (2P\_0 - P\_1)$ and then apply $M\_2$ to $\begin{bmatrix}
P\_{g} \\
P\_0 \\
P\_1 \\
P\_2
\end{bmatrix}$ you will end up with the following situation:
[![enter image description here](https://i.sstatic.net/m9l1L.png)](https://i.sstatic.net/m9l1L.png)
Here curve $a$ is constructed using control points $[P\_{g}, P\_0, P\_1, P\_2]$ and curve $b$ with $[P\_0, P\_1, P\_2, P\_3]$. Naturally, the same can be done at the end of the curve by creating a ghost point $P\_g = 2P\_n - P\_{n-1}$. If you need the matrix you will have to substitute $(2P\_0 - P\_1)$ for $P\_g$ and find out which functions act on $P\_0$ and $P\_1$ by writing out the equations and collecting the terms.

> **Comments:**
> **username_0**: Great, adding an extra point does the trick, thank you! Next step will be for me to understand why we can't apply the same logic than for a quadratic bezier and why we need to introduce that knot vector, but for the time being, adding a point at the beginning works! Thank you so much =]  

---

