B-spline knot insertion

We might want to insert an extra knot into a B-spline to allow us to edit the shape of the curve. Ideally we would like to be able to insert a knot at a given value of \(t\) without modifying the shape of the curve. We can do this easily using a process called knot insertion, that deletes \(k-1\) knots from a curve of degree \(k\) and inserts \(k\). In a cubic B-spline this means two knots are deleted and replaced with three new knots. To calculate the location of the new knots we can use:

$$Q_i(t)=(1-a_{i})P_{i-1}+a_{i}P_i$$

$$a_{i,r}=\frac{t-t_i}{t_{i+n-r}-t_i}$$

where \(t_i\) is the knot for which \(t_i\leq t \leq t_{i+1}\). Then we replace control points \(P_{i-k+1},\ldots,P_{i-1}\) with \(Q_{i-k+1},\ldots,Q_i\). In the case of a cubic B-spline as below we remove \(P_{i-2}\) and \(P_{i-1}\) (control points in grey) and replace them with \(Q_{i-2},Q_{i-1},Q_i\) (circles in orange). If we were to delete the control points in grey and insert those in orange the shape of the curve would remain the same.