6
$\begingroup$

I have the following code to plot value of a bspline curve but it doesn't evaluate when I specify weights and knots and I'm not sure what's going wrong, the weights and knots vectors have the correct length (and if I change them I get an error) but for f I end up with a function that doesn't evaluate.

knots = {0,1,2,3,4,5,6,7,8};
points = {{0,0},{1/2,1},{1,1/4},{3/2,1},{2,0}};
weights = {1,1,1,1,1};
degree= 3;
f = BSplineFunction[points,SplineDegree->degree, SplineKnots->knots,SplineWeights->weights]
g = BSplineFunction[points,SplineDegree->degree]
g[0]
f[0]

Here's a screenshot of my output using Mathematica 10.3 on Windows:

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ It seems to not like your knots. knots={0, 0, 0, 0, 1, 2, 2, 2, 2} works. I note however the corresponding BSplineCurve works fine with your knots. $\endgroup$
    – george2079
    Commented Mar 22, 2016 at 20:08
  • $\begingroup$ Ahh, it's annoying :) Maybe it's a bug? $\endgroup$
    – okmatija
    Commented Mar 22, 2016 at 20:53
  • $\begingroup$ No, the knots can not be just any sequence with the right length. It must fulfill specific conditions. Try for instance knots = {0, 0, 0, 0, .5, 1, 1, 1, 1}; $\endgroup$ Commented Mar 22, 2016 at 21:28
  • $\begingroup$ Usually an admissible B-spline has the extreme knots repeated according to the degree of the spline. In the case of @george's knot sequence, you have a multiplicity of 4 in the first and last knots, corresponding to a cubic B-spline. $\endgroup$ Commented Mar 22, 2016 at 22:33
  • $\begingroup$ If memory serves the multiplicity is only required if you want the curve to pass through the end control points. Note BSplineCurve works without the multiplicity, (and does not hit the end points). $\endgroup$
    – george2079
    Commented Mar 22, 2016 at 23:05

1 Answer 1

5
$\begingroup$

For the B-spline curve:

$$ \overset{\rightharpoonup }{C}(u)=\sum _{i=0}^n N_{i,p}(u) \overset{\rightharpoonup }{P}_i \text{ }\qquad (a\leq u\leq b) $$

where, $P_i$ is the control point, the $N_ {i, p} (u)$ are the $p$th - degree B-spline basis functions defined on the non-periodic (and non-uniform) knot vector:

$\{\underbrace {a,\cdots ,a}_{p+1},u_{p+1},\cdots u_{m-p-1},\underbrace {b,\cdots,b}_{p+1}\}$

Here, $m=n+p+1$ and the domain of curve is $[u_p,u_{n}]$

For your example

knots = {0,1,2,3,4,5,6,7,8};
points = {{0,0},{1/2,1},{1,1/4},{3/2,1},{2,0}};
weights = {1,1,1,1,1};
degree= 3;

f = BSplineFunction[points, SplineDegree -> degree, 
                    SplineKnots -> knots, SplineWeights -> weights]

So the spline function domain is $[3,5]$, you can verify it via the below code:

GraphicsColumn[
  {ParametricPlot[f[u], {u, 3, 5}], 
   Graphics[
    {BSplineCurve[points, SplineDegree -> degree, 
                  SplineKnots -> knots, SplineWeights -> Automatic]}]}]

enter image description here

Owing to the built-in BSplineFunction[] using the default domain $[0,1]$ to generate the spline icon, so f will lost the spline icon like this:

enter image description here

Normalize the knots to $[0,1]$,

BSplineFunction[
  points, SplineDegree -> degree, 
  SplineKnots -> {-(3/2), -1, -(1/2), 0, 1/2, 1, 3/2, 2, 5/2}, 
  SplineWeights -> Automatic]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, this works for me. Also, I think you mean that the domain of the curve is $[u_p, u_{n+1}]$. See this link for example, the Piegl and Tiller book isn't as explicit on that point $\endgroup$
    – okmatija
    Commented Mar 28, 2016 at 11:01
  • $\begingroup$ @mkm No, Piegl discussed that domain on page 152 in chapter 12: Data exchange of The NURBS Book. $\endgroup$
    – xyz
    Commented Mar 28, 2016 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.