Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Create B-Spline curve using MATLAB

  1. Oct 2, 2013 #1
    I need a MATLAB expert to guide me on how to create a b-spline curve using MATLAB Software. I understand the B-spline basis function calculations for zeroth and first degree but I have no idea on how to calculate for the 2nd degree. I need a favor on that part. I am currently working on my final year project titled INTERPOLATION OF PLANAR CURVE WITH DIFFERENT PARAMETERISATION. Thanks in Advance.
    Last edited: Oct 2, 2013
  2. jcsd
  3. Oct 3, 2013 #2
    Just like you linearly interpolate the 0th degree basis functions to get the 1st degree basis functions, you have to linearly interpolate the 1st degree basis functions to get the 2nd degree. The recursive B-spline basis formula tells you how to do that.

    Here's some code snippets for MATLAB does B-spline curve evaluation for a degree-p B-spline curve with knot vector U at parameter value u with control point array C:

    Code (Text):

    function S = bcurve_eval(u,p,U,C)
        uspan = findKnotSpan(u,p,U);
        Nu = getBasisFuncs(u,p,U,uspan);
        S = zeros(1,numel(C(1,:)));
        for i=0:p
            index = uspan-p+i;
            S = S + C(index+1,:) * Nu(i+1);
    Code (Text):

    function i = findKnotSpan(u,p,U)
        k = numel(U)-1;
        n = k-p-1;
        if u == U(n+1 +1)
            i = n;
        l = p +1;
        h = n+1 +1;
        i = floor((l+h)/2);
        while u < U(i) || u >= U(i+1)
            if u < U(i)
                h = i;
                l = i;
            i = floor((l+h)/2);
        i = i-1;
    Code (Text):

    function N = getBasisFuncs(u,p,U,i)
        left = zeros(1,p+1);
        right = zeros(1,p+1);
        N = zeros(1,p+1);
        N(1) = 1;
        for j=1:p
            left(j+1) = u - U(i+1-j +1);
            right(j+1) = U(i+j +1) - u;
            s = 0;
            for r=0:j-1
                temp = N(r +1) / (right(r+1 + 1) + left(j-r +1));
                N(r +1) = s + right(r+1 +1) * temp;
                s = left(j-r +1) * temp;
            N(j +1) = s;
    Hope that helps. Let me know if you have questions.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook