Other way or suggestion to build Bezier surface
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, My name Malina from Malaysia and i'm a student. I'm working with Bezier and B-spline modelling. I'm using Matlab 2018. My question is
(1)I having a problem to build Bezier surface because the function that u suggest in internet cannot found and do not exist in my matlab. For example Got error. Can you help to solve my problem with new suggestion that i can be use in my Matlab.
(2)My second question is can you give example some example of how to build B-spline curve because the guideline 'help' in Matlab dont have any example on B-spline curve like Bezier curve. I know the Bezier curve we can use Bernstein function. But B-spline do not have any example and some figure of B-spline curve.
Hope you can help me with this two question.
0 comentarios
Respuestas (1)
Aditya
el 3 de Feb. de 2025
Hi Malina,
1) Building a Bézier Surface in MATLAB:
If you don't have built-in functions for Bézier surfaces in your version of MATLAB, you can create a Bézier surface using the Bernstein polynomial basis. Here's a basic example of how to construct a Bézier surface:
% Define control points for a Bézier surface
controlPoints = zeros(4, 4, 3); % Example with 4x4 control points in 3D
% Example control points (you should define these based on your specific surface)
controlPoints(:, :, 1) = [0 1 2 3; 0 1 2 3; 0 1 2 3; 0 1 2 3]; % X-coordinates
controlPoints(:, :, 2) = [0 0 0 0; 1 1 1 1; 2 2 2 2; 3 3 3 3]; % Y-coordinates
controlPoints(:, :, 3) = [0 1 0 1; 1 2 1 2; 0 1 0 1; 1 2 1 2]; % Z-coordinates
% Define parameters for Bézier surface
u = linspace(0, 1, 50);
v = linspace(0, 1, 50);
[U, V] = meshgrid(u, v);
% Initialize surface points
surfPoints = zeros(size(U, 1), size(V, 2), 3);
% Calculate Bézier surface points
for i = 1:4
for j = 1:4
B_ij = bernstein(i-1, 3, U) .* bernstein(j-1, 3, V);
for k = 1:3
surfPoints(:, :, k) = surfPoints(:, :, k) + B_ij .* controlPoints(i, j, k);
end
end
end
% Plot Bézier surface
surf(surfPoints(:, :, 1), surfPoints(:, :, 2), surfPoints(:, :, 3));
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Bézier Surface');
% Helper function for Bernstein polynomial
function B = bernstein(i, n, t)
B = nchoosek(n, i) .* (t.^i) .* ((1-t).^(n-i));
end
2) Building a B-spline Curve in MATLAB
For B-spline curves, you can use the spapi function from the Spline Toolbox for constructing a spline interpolant. Here's a simple example:
% Define knot vector and control points
knots = [0 0 0 1 2 3 4 4 4]; % Example knot vector for cubic B-spline
controlPoints = [0 1 2 3 4; 0 1 0 1 0]; % Control points (2D example)
% Create B-spline using spapi
degree = 3; % Degree of the B-spline
bSpline = spapi(knots, controlPoints);
% Evaluate B-spline curve
t = linspace(0, 4, 100); % Parameter values
curvePoints = fnval(bSpline, t);
% Plot B-spline curve
plot(curvePoints(1, :), curvePoints(2, :), 'b-', 'LineWidth', 2);
hold on;
plot(controlPoints(1, :), controlPoints(2, :), 'ro--'); % Control polygon
xlabel('X');
ylabel('Y');
title('B-spline Curve');
legend('B-spline Curve', 'Control Polygon');
0 comentarios
Ver también
Categorías
Más información sobre Spline Construction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!