Bicubic B-spline surface

6 views (last 30 days)
Anna Garcia Teruel
Anna Garcia Teruel on 2 Jun 2016
Answered: Aditya on 3 Feb 2025
Hi,
I have been looking at the different spline functions that Matlab offers (<http://uk.mathworks.com/help/curvefit/construction.html)>, but haven´t quite found what I need.
I have a set of vertices in 3D, the two knot vectors (so that start and end of the spline functions are defined) and the order of the spline functions. I would like to obtain the parametric equations, so that I can plot the splines or spline surfaces and the vertices and see the actual shape of the approximated surface and the difference relative to the vertices.
I have started implementing the mathematical equations but I am not sure I am gonna be able to plot what I want after.
Are there any in-built functions I could use to calculate what I need? And what would be the best way to plot the surfaces? Or do I need a CAD program for this?
I will appreciate any help.
Anna

Answers (1)

Aditya
Aditya on 3 Feb 2025
Hi Anna,
To work with splines in 3D and visualize them in MATLAB, you can use the nrbmak and nrbeval functions from the NURBS toolbox, which is a part of the Geometry and Topology Toolbox (G+T Toolbox). This toolbox allows you to create and manipulate NURBS (Non-Uniform Rational B-Splines), which are a powerful way to represent curves and surfaces in 3D.
Here's an example of how you might implement these steps:
% Assuming you have the following:
% - controlPoints: a 3D array of control points (vertices)
% - uKnotVector, vKnotVector: knot vectors for the two parametric directions
% - p, q: orders of the spline in the u and v directions
% Example control points (3D array: [x, y, z] dimensions)
controlPoints = rand(4, 4, 3); % Replace with your actual control points
% Example knot vectors
uKnotVector = [0 0 0 1 2 2 2]; % Replace with your actual knot vector
vKnotVector = [0 0 0 1 2 2 2]; % Replace with your actual knot vector
% Orders of the splines
p = 2; % Order in u direction
q = 2; % Order in v direction
% Create the NURBS surface
nurbsSurface = nrbmak(controlPoints, {uKnotVector, vKnotVector});
% Evaluate the NURBS surface
numPoints = 50; % Number of points to evaluate along each parameter direction
u = linspace(0, 1, numPoints);
v = linspace(0, 1, numPoints);
[U, V] = meshgrid(u, v);
surfacePoints = nrbeval(nurbsSurface, {U, V});
% Plot the NURBS surface
surf(surfacePoints(1, :, :), surfacePoints(2, :, :), surfacePoints(3, :, :), ...
'EdgeColor', 'none', 'FaceAlpha', 0.5);
hold on;
% Plot the control points
plot3(controlPoints(:, :, 1), controlPoints(:, :, 2), controlPoints(:, :, 3), 'ro-');
xlabel('X');
ylabel('Y');
zlabel('Z');
title('NURBS Surface with Control Points');
axis equal;
grid on;

Community Treasure Hunt

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

Start Hunting!