Nodes number in BSpline Matlab

2 views (last 30 days)
Bowen
Bowen on 17 Oct 2013
Answered: Aditya on 5 Feb 2025
Hi everyone,
I am using Matlab function spmak() to give me several Bsplines. I give the control points and knots, and then I can get the smooth curve, like the following picture. Black nodes are the control points, and red nodes come from this expression: red=fnplt(sp,[knots3(3),knots3(13)])
My question is that I cannot control the number of the red nodes from fnplt function. How could I only choose 60 points uniformly from all these points? I know I can just select every two points. But it's not uniform and convenient.
Thanks.

Answers (1)

Aditya
Aditya on 5 Feb 2025
Hi Bowen,
To extract a specific number of uniformly spaced points from a B-spline curve generated by MATLAB's spmak and fnplt functions, you can follow these steps:
% Example control points and knots (replace with your data)
controlPoints = [0 1 2 3 4 5; 0 1 0 -1 0 1]; % Example 2D control points
knots = [0 0 0 1 2 3 4 4 4]; % Example knots
% Create B-spline using spmak
sp = spmak(knots, controlPoints);
% Evaluate the B-spline curve using fnplt
% Get points of the B-spline curve
[x, y] = fnplt(sp, [knots(3), knots(13)]);
% Total number of points generated by fnplt
numPoints = length(x);
% Desired number of uniformly spaced points
desiredPoints = 60;
% Generate indices for uniformly spaced points
uniformIndices = round(linspace(1, numPoints, desiredPoints));
% Select uniformly spaced points
uniformX = x(uniformIndices);
uniformY = y(uniformIndices);
% Plot the results
figure;
plot(x, y, 'r-', 'DisplayName', 'B-spline Curve');
hold on;
plot(controlPoints(1, :), controlPoints(2, :), 'ko', 'DisplayName', 'Control Points');
plot(uniformX, uniformY, 'bo', 'DisplayName', 'Uniform Points');
legend;
title('B-spline Curve with Uniformly Spaced Points');
xlabel('X');
ylabel('Y');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!