Global curve interpolation with end derivatives specified (setting up the matrix equation).

254 Views Asked by At

I am working through The NURBS Book. Example 9.1 shows us how to interpolate the points $$\{Q_k\} = \{(0,0),(3,4),(-1,4),(-4,0),(-4,-3)\}$$ with a cubic B-spline curve. Using the chord length method we obtain the parameters $$\overline{u_0}=0, \overline{u_1} = \frac{5}{17}, \overline{u_2}=\frac{9}{17},\overline{u_3}=\frac{14}{17},\overline{u_4}=1.$$ Next, using the averaging method, we obtain the knots $$U = \{0,0,0,0,\frac{28}{51},1,1,1,1\}.$$ The system of linear equations becomes $$ \begin{bmatrix} 1&0&0&0&0\\ N_{0,3}(\frac{5}{17})&N_{1,3}(\frac{5}{17})&N_{2,3}(\frac{5}{17})&N_{3,3}(\frac{5}{17})&0\\ N_{0,3}(\frac{9}{17})&N_{1,3}(\frac{9}{17})&N_{2,3}(\frac{9}{17})&N_{3,3}(\frac{9}{17})&0\\ 0&N_{1,3}(\frac{14}{17})&N_{2,3}(\frac{14}{17})&N_{3,3}(\frac{14}{17})&N_{4,3}(\frac{14}{17})\\ 0&0&0&0&1 \end{bmatrix} \begin{bmatrix} \mathbf{P_0}\\\mathbf{P_1}\\\mathbf{P_2}\\\mathbf{P_3}\\\mathbf{P_4} \end{bmatrix} =\begin{bmatrix}\mathbf{Q_0}\\\mathbf{Q_1}\\\mathbf{Q_2}\\\mathbf{Q_3}\\\mathbf{Q_4}\end{bmatrix}.$$ The solution I obtained for the control points (which seems correct) is $$\{P_k\}=\{(0,0),(7.32,3.69),(-2.96,6.68),(-4.49,-0.67),(-4,-3)\}.$$

Next I want to interpolate the same points, but this time specify the first derivatives at the endpoints, but I am having some trouble.

Consider the same $\{Q_k\}$ as above. According to the book, the parameters $\overline{u_k}$ stay the same, the knot vector $U$ is computed by $$u_0=\cdots=u_p=0$$ $$u_{m-p}=\cdots u_{m}=1$$ $$u_{j + p + 1}=\frac{1}{p}\sum_{i=j}^{j+p-1}\overline{u_i},j=0,\dots,n-p+1$$ where $m=n+p+3$ and $p=3$, and the following two equations need to be added as the second and second-to-last (respectively) equations in the linear system: $$-\mathbf{P_0}+\mathbf{P_1}=\frac{u_{p+1}}{p}\mathbf{D_0}$$ $$-\mathbf{P_{n+1}}+\mathbf{P_{n+2}}=\frac{1-u_{m-p-1}}{p}\mathbf{D_n},$$

where $\mathbf{D_0}$ and $\mathbf{D_n}$ are the derivatives at the endpoints. I am not sure if I am computing the right knots, and I don't quite know how to insert those two equations into the linear system. What I got was the following: $$U=\{0,0,0,0,0.27,0.55,0.78,1,1,1,1\}$$ and $$\begin{bmatrix} 1&0&0&0&0&0&0\\ -1&0&1&0&0&0&0\\ N_{0,3}(\frac{5}{17})&0&N_{1,3}(\frac{5}{17})&N_{2,3}(\frac{5}{17})&N_{3,3}(\frac{5}{17})&0&0\\ N_{0,3}(\frac{9}{17})&0&N_{1,3}(\frac{9}{17})&N_{2,3}(\frac{9}{17})&N_{3,3}(\frac{9}{17})&0&0\\ 0&0&N_{1,3}(\frac{14}{17})&N_{2,3}(\frac{14}{17})&N_{3,3}(\frac{14}{17})&0&N_{4,3}(\frac{14}{17})\\ 0&0&0&0&-1&0&1\\ 0&0&0&0&0&0&1 \end{bmatrix} \begin{bmatrix} \mathbf{P_0}\\\mathbf{P_1}\\\mathbf{P_2}\\\mathbf{P_3}\\\mathbf{P_4}\\\mathbf{P_5}\\\mathbf{P_6} \end{bmatrix} =\begin{bmatrix}\mathbf{Q_0}\\\frac{u_{p+1}}{p}\mathbf{D_0}\\\mathbf{Q_1}\\\mathbf{Q_2}\\\mathbf{Q_3}\\\frac{1-u_{m-p-1}}{p}\mathbf{D_n}\\\mathbf{Q_4}\end{bmatrix}.$$ However none of the different derivative values I specified give me any answer remotely close to interpolating the points. In most cases the software told me that my matrix is not even invertible. I would most appreciate any help you can give me to figuring this out. Are my knots and matrix right or wrong, and what can I do to fix them?

1

There are 1 best solutions below

1
On BEST ANSWER

Everything looks OK, to me, except for the error that @mathreader pointed out in his comment.

The second equation is $$ -\mathbf{P_0}+\mathbf{P_1}=\frac{u_{p+1}}{p}\mathbf{D_0} $$ so the second row of your matrix should $$ [-1,1,0, 0,0,0,0] $$ For similar reasons, the second-to-last row should be $$ [0,0,0,0,0,-1,1] $$ I didn't check your knots. But you have the right number of knots, at least, and their precise values don't matter very much. As long as your knots are not horribly wrong, you will still get a curve that interpolates the input data.