Hi Priyabrata,
To create a closed B-spline curve of degree ‘k-1’, you need to append the initial ‘k-1’ points of the x and y vectors to the end of their respective vectors.
For instance, if the vector x is [0, 1, 2, 4, 3] and the vector y is [0, 2, 4, 2, 0], and the degree is 3, you should transform these vectors to [0, 1, 2, 4, 3, 0, 1, 2] and [0, 2, 4, 2, 0, 0, 2, 4], respectively. This transformation can be achieved using the following commands:
Once you have the updated vectors, you can utilize the basis function equation to generate the spline curve.
Below is a sample code snippet for the basis function, followed by an example demonstrating how to call this function.
function N = basisFunction(i, k, t, knots)
if knots(i) <= t && t < knots(i+1)
if knots(i+k-1) - knots(i) == 0
term1 = ((t - knots(i)) / (knots(i+k-1) - knots(i))) * basisFunction(i, k-1, t, knots);
if knots(i+k) - knots(i+1) == 0
term2 = ((knots(i+k) - t) / (knots(i+k) - knots(i+1))) * basisFunction(i+1, k-1, t, knots);
function [splineX, splineY] = closedBSpline(k, x, y, numPoints)
tParam = linspace(k-1, n, numPoints);
splineX = zeros(1, numPoints);
splineY = zeros(1, numPoints);
N = basisFunction(i, k, tParam(j), knot);
splineX(j) = splineX(j) + N * x(i);
splineY(j) = splineY(j) + N * y(i);
plot(x, y, 'o-', 'DisplayName', 'Control Points');
plot(splineX, splineY, 'r-', 'DisplayName', 'B-Spline');
title('Closed Parametric B-Spline');
By applying the code provided above, you can create a cubic B-spline that results in the following graph. The subsequent code details the steps required to achieve this implementation.
[splineX, splineY] = closedBSpline(k, x, y, numPoints);
To explore more about basis function, please follow the given link.
I hope this helps in solving the query.