Create B-Spline curve using MATLAB

In summary, the conversation revolves around creating a B-spline curve using MATLAB Software, particularly on calculating for the 2nd degree. The expert suggests using recursive B-spline basis formula and provides code snippets for MATLAB to evaluate the curve. The project topic is interpolation of planar curves with different parameterisation.
  • #1
Praba89
1
0
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:
Physics news on Phys.org
  • #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:
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);
    end
end

Code:
function i = findKnotSpan(u,p,U)
    k = numel(U)-1;
    n = k-p-1;
    if u == U(n+1 +1)
        i = n;
        return
    end
    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;
        else
            l = i;
        end;
        i = floor((l+h)/2);
    end
    i = i-1;
end

Code:
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;
        end
        N(j +1) = s;
    end
end

Hope that helps. Let me know if you have questions.
 
  • Like
Likes Yaaqob Saad and (deleted member)

1. What is a B-Spline curve?

A B-Spline curve is a type of mathematical curve that is commonly used in computer graphics and data analysis. It is made up of a series of polynomial segments connected together to form a smooth curve. B-Spline curves are particularly useful because they can accurately represent complex shapes and can be easily manipulated and adjusted.

2. How can I create a B-Spline curve using MATLAB?

To create a B-Spline curve using MATLAB, you can use the spline function. This function takes in a set of control points and generates a B-Spline curve that passes through those points. You can also specify the degree of the curve and the number of points to be generated. You can find more detailed instructions and examples in the MATLAB documentation.

3. What is the degree of a B-Spline curve?

The degree of a B-Spline curve refers to the degree of the polynomial segments that make up the curve. This determines the smoothness of the curve and the number of control points needed to define it. The higher the degree, the more flexible the curve will be, but also the more control points are required.

4. Can I edit a B-Spline curve after creating it in MATLAB?

Yes, you can edit a B-Spline curve in MATLAB by adjusting the control points or by changing the degree of the curve. You can also manipulate the curve by adding or removing control points or by changing their positions. These changes will automatically update the B-Spline curve.

5. How can I use B-Spline curves in data analysis?

B-Spline curves can be used in data analysis to represent and analyze complex data sets. They can be used to interpolate between data points, smooth out noisy data, or to visualize trends in the data. B-Spline curves are particularly useful when working with large and complex data sets, as they can accurately represent the data without being affected by outliers or noise.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top