# Algorithm for trimming b-spline

I'm stuck with developing algorithm to trim b-spline so it begins at certain point without changing it's shape. I'm using these formulas: link. I have already implemented inserting knot at given t. Let me show you example of what I'm trying to do.

Control points of my spline are: ((0, 0), (19, 0), (0, 12), (28, 38), (56, 14), (34, 0), (56, 0))
Knot vector of original spline is: (0, 0, 0, 0, 0,25, 0,5, 0,75, 1, 1, 1, 1)
Degree of spline: 3.

Now I would like add a knot at let's say 0.3 and then cut all that preceeds 0.3 without changing the shape of curve so it starts at inserted point.

-
You're supposed to be able to use the Cox-de Boor recursion for something like this (analogous to the use of the de Casteljau recursion to cut off Bézier curves). –  J. M. is back. Jul 17 '12 at 12:21

Suppose your spline curve is $C(t)$, and let $m$ denote its degree. You need to insert the knot $t = 0.3$ repeatedly until its multiplicity is $m$. So, in your example, this will give you a new curve whose knot sequence is $(0,0,0,0,0.25,0.3,0.3,0.3, 0.5, 0.75, 1,1,1,1)$. Let $Q_1,Q_2, \ldots, Q_n$ be the control points of this curve, in your example, $n$ will be equal to 10.
The point $C(0.3)$ will be a control point of the new refined curve; call it $Q_r$. This control point divides the list of control points into two halves. The first half of the curve will be defined by the control points $Q_1,Q_2, \ldots, Q_r$ and the second half will be defined by the control points $Q_r, \ldots, Q_n$. The first half will have knots $(0,0,0,0,0.25,0.3,0.3,0.3, 0.3)$, and the second half will have knots $(0.3, 0.3, 0.3, 0,3, 0.5, 0.75, 1,1,1,1)$. If you want to, you can normalise each of these knot sequences to the range $[0,1]$. For example, normalising the first half would give (0,0,0,0, 2.5/3, 1,1,1,1).