1

I have consider a 1-D problem to figure out how B-splines work. I assume that I want to interpolate on x-values 1,2,3 and 4. I gave random values to my control points, namely w1=0, w2=-1, w3=3 and w4=2. I consider the Basis functions for cubic B-spline $B_0=(1-u)^3/6, B_1=(3u^3-6u^2+4)/6, B_2=(-3u^3+3u^2+3u+1)/6, B_3=u^3/6$. Based on the formula $F(x)= \sum Wi Bi(x)$. I also know that u=x/nx where nx=4 in my case. So \begin{equation} F= 0\times B_0+(-1)\times B_1+3\times B_2+2\times B_3$, \end{equation}

after substitute the basis functions and doing some calculationsI end up with

\begin{equation} F(u)= 1/6 x (-10u^3+15u^2+9u-1). \end{equation}

At x=1 u=1/4 so F(1/4)= 65/192 which is not equal to zero as I expected. Since the control point at x=1 is equals zero then I have to end up with zero right?Because the spline in the end it has to be function that goes through the control points so we can check that. Can you please give me some hint about what I doing wrong? I will really appreciate.

enter image description here

  • Closely related to this question: http://math.stackexchange.com/questions/699113/relation-of-cubic-b-splines-with-cubic-splines and this one http://math.stackexchange.com/questions/702980/cubic-b-spline-interpolation. Both are from this same user. I gave it two good shots, but was not successful in solving his problems. I'll let someone else try, this time. – bubba Mar 13 '14 at 09:42
  • Your explanations was really really good and I am really appreciate. But what is confused me and I am still confuse about is for the knots. You mention that the knot vector $1,2,3,4$ would not work. If I have 4 x-values as presented above I can't use B-spline interpolation? This is what I mean with the $1,2,3,4.$ You told me to write it like this $(0,0,0,0,1,2,3,4,5,5,5,5)$. This is what it doesn't make sense to me and confuse me. The points that I want to interpolate are the $1,2,3,4$. – user105627 Mar 13 '14 at 10:16

2 Answers2

4

If you want to interpolate values $y_1$, $y_2$, $y_3$, $y_4$ at values $x = 1,2,3,4$, then the required "blending" or "basis" functions are: $$ \begin{align} g_1(x) &= \tfrac16 (24 - 26 x + 9 x^2 - x^3) \\ g_2(x) &= \tfrac12 (-12 + 19 x - 8 x^2 + x^3) \\ g_3(x) &= \tfrac12 (8 - 14 x + 7 x^2 - x^3) \\ g_4(x) &= \tfrac16 (-6 + 11 x - 6 x^2 + x^3) \end{align} $$ These give the curve $$ C(x) = g_1(x)y_1 + g_2(x)y_2 + g_3(x)y_3 + g_4(x)y_4 = \sum_{i=1}^4 y_i g_i(x) \qquad (*) $$ You can easily check that $C(i) = y_i$ for $i=1,2,3,4$.

In your particular case, you have $y_1=0$, $y_2=-1$, $y_3=3$, $y_4=2$, and the curve becomes $$ C(x) = \tfrac16 (96 - 161 x + 75 x^2 - 10 x^3) $$ Again, you can easily check that this has the right properties.

In some sense, this is not a very interesting "spline" because it has only one cubic segment. But, if you insist on using a linear combination of simple cubic basis functions, then this is what you'll always get. The "$g$" functions given above are the only basis functions that will give the sort of interpolation you seem to want.

Where do the basis functions $g_1$, $g_2$, $g_3$, $g_4$ come from? They are actually the Lagrange polynomials for the nodes $x_1 = 1$, $x_2 = 2$, $x_3 = 3$, $x_4 = 4$. There are (at least) two ways to construct them. The most elementary approach is to assume that $C$ has the form $$ C(x) = ax^3 + bx^2 + cx + d \qquad (**) $$ The requirement that $C(x_i) = y_i$ for $i=1,2,3,4$ gives us four linear equations, which we can solve to get $a$, $b$, $c$, $d$ in terms of $y_1$, $y_2$, $y_3$, $y_4$. We plug the solutions back into equation $(**)$, and rearrange terms, and we'll get something in the form of (*), from which we can identify $g_1$, $g_2$, $g_3$, $g_4$. This is a very simple special case of the "interpolating spline" technique that several people have suggested to you.

The more clever approach uses the concept of Lagrange polynomials. A little thought shows that $(*)$ will give us the interpolation we need if the functions $g_i$ have the property $g_i(x_j) = \delta_{ij}$. In other words, $g_i(x_j) = 1$ if $i=j$ and $g_i(x_j) = 0$ if $i \ne j$. We can construct polynomials with this property quite easily. For example, we can define $g_2$ by: $$ g_2(x) = \frac{(x-x_1)(x-x_3)(x-x_4)}{(x_2-x_1)(x_2-x_3)(x_2-x_4)} $$ It's clear that this is a cubic polynomial that has the desired properties. If you plug in $x_1 = 1$, $x_3 = 3$, $x_4 = 4$, you'll get $g_2(x) = \tfrac12 (-12 + 19 x - 8 x^2 + x^3)$. The other three $g_1$, $g_3$, $g_4$ can be constructed similarly.

bubba
  • 44,617
  • How did you end up with these basis functions? Also you wrote the curve $C(u)$ as a function of $x$. What am I supposed to substitute on my curve the value $u=1/4$ or the value $x=1$? – user105627 Mar 13 '14 at 11:15
  • Sorry. Removed the $u$ variable. Use your $x$ values. – bubba Mar 13 '14 at 11:18
  • How did you find the new basis functions $g_1(x),g_2(x),g_3(x),g_4(x)$? – user105627 Mar 13 '14 at 11:27
  • First, please confirm that they solve your problem. If they don't, then I don't want to spend any time explaining them. – bubba Mar 13 '14 at 11:33
  • I had made the substitution on $C(x)$ with $x=1,2,3,4$ and it works fine I ended up with $y=0,-1,3,2$ respectively. – user105627 Mar 13 '14 at 11:55
  • That is why I want to understand how did you find the corresponding basis functions. – user105627 Mar 13 '14 at 11:56
  • Please see the additions to my answer. – bubba Mar 14 '14 at 03:55
  • Why I cannot use the basis functions that I mentioned before? If not when I will be able to use them? People used to give just the formula I typed below $(S(x)$, so I thought that I will just use these basis functions every time. – user105627 Mar 14 '14 at 10:38
  • Your basis functions don't give interpolation. – bubba Mar 15 '14 at 00:23
  • If they don't give interpolation so what that basis functions stands for? – user105627 Mar 16 '14 at 16:14
  • Also, we use the b-splines to get an interpolation formula that is continuous in both first and second derivatives. This curve will have the form as mention on equation $ (*)$. I was trying to check if these properties holds for the basis functions $g_1,g_2,g_3,g_4$. As shown above: $g_1(x) \quad x<1$, $g_2(x) \quad 1\leq x \leq 2$, $g_3(x) \quad 2 \leq x \leq 3$ and $ g_4(x) \quad 3 \leq x \leq 4$. At $x=1$ $g'_1(x) \neq g'_2(x)$. So the first derivative is discontinuous in the way I solved it. – user105627 Mar 16 '14 at 17:48
  • You're not supposed to shift these "g" basis functions. Just leave them as is on the interval $[1,4]$. They are polynomials, so they have continuous derivatives of all orders. Therefore the function $C$ defined by equation (*) has this same continuity. – bubba Mar 17 '14 at 11:26
  • I have read that with a uniform B-spline we cannot change the basis functions (they are fixed because all the knots are equispaced). In this case that I had consider with $[1,4]$ why I have to find the basis functions? When I will be able to use the basis functions $B_0,B_1,B_2,B_3$ (mentioned above)? – user105627 Mar 17 '14 at 11:29
  • Your basis functions (or shifted versions of them) can be used in regions of the curves where you don't want interpolation. At end points, people usually do want interpolation, so those functions won't work there. – bubba Mar 17 '14 at 23:57
  • If the b-splines are not a technique of interpolation what is the purpose of this method? – user105627 Mar 18 '14 at 14:57
2

Cubic B-splines have $C^2$ continuity, but are not "interpolating" in general, i.e., they pass NEAR their control points, but not through them. Thus your expectation that $F(1/4)$ should be $0$ is mistaken.

("Interpolating" is used as an adjective by spline-ologists, and is contrasted with "approximating". B-splines are, in general, approximating splines rather than interpolating splines.)

John Hughes
  • 100,827
  • 4
  • 86
  • 159
  • For the $F(1/4)\approx 0.34$ which is pretty close to the control point $0$. But at $x=2$ $u=1/2$ and $F(1/2)=1$ and the control point $w_1=-1$ which is quite far the same holds for $x=3$ $u=3/4$ where $F(3/4)\approx 5.88$ and the corresponding control point was $w_2=3$. Why for the other control points there is such a big difference between the $F$ value and the control points? I did something wrong? – user105627 Mar 12 '14 at 23:26
  • I didn't actually check your work. I just happened to know that B-splines generally don't interpolate their control points, so you should not have expected this one to do so. To be honest, I can't make much sense of what you wrote with "u" and "x" both appearing in your formula. It might help others answer if you gave a reference for your B-spline notation; it's been written down many many ways over the years. – John Hughes Mar 12 '14 at 23:44
  • Here is the formula: $S(x)= \sum_{i=0}^3 B_i(u) w_{i+k}$ where $i=\lfloor {x/n_x} \rfloor-1$ and $u=x/n_x- \lfloor {x/n_x}\rfloor$. The basis functions are described above. – user105627 Mar 13 '14 at 09:31