필터 지우기
필터 지우기

bezier surface plotter question

조회 수: 1 (최근 30일)
mohammad azsad
mohammad azsad 2014년 11월 20일
댓글: Dominik Cech 2021년 8월 27일
i want to write program of bezier surface but it is wrong please help me this program that i wrote:
x=[12 23 13 4 5]';y=[12 4 15 23 7]';z=[1 14 25 2 7]'; p=[x,y,z];
bez = [];
n = size(p, 1) - 1;
O = 1; for v = 0:0.01:1; for u = 0:0.01:1;
suma = [0 0 0];
for i=0:n
for j=0:n
if i==0, res = 1;
elseif n==0, res = 0;
else
res = 1;
for a=1:i
res = res*((n - i + a)/a);
end
end
if j==0, res1 = 1;
elseif n==0, res1 = 0;
else
res1 = 1;
for a1=1:j
res1 = res1*((n - j + a1)/a1);
end
end
suma = suma + p(i+1, :)*res*(u^i)*((1 - u)^(n - i))*res1*(v^j)*((1 - v)^(n - j)) ;
end
bez(O, :) = suma;
O=O+1
end
end end
plot3(x,y,z,'k') hold on grid on
if ischar(fig) symbol = fig; elseif n < 30 symbol = 'o'; else symbol = '.';
end
for j = 1:n hPoints = plot3(p(:,1), p(:,2),p(:,3), symbol); hold on; end hold on, hbc = plot3(bez(:, 1), bez(:, 2), bez(:, 3), 'LineWidth', 3, 'Color', 'b'); % plots the Bezier curve legend([hbc], {'Bezier curve'}) title(sprintf('number of points: %d', n+1))
and the formula is
where is p is control points
and

답변 (1개)

amina lk
amina lk 2014년 12월 2일
this control point of curve ,you have to use 16 control point for you to draw a bezier surface
look this exemple of bezier surf
clear; clf; % Blending Function % Parametric Values u= 0 : 0.05 : 1; for i=1:21 U(i,1)=u(i)^3; U(i,2)=u(i)^2; U(i,3)=u(i); U(i,4)=1; end w= 0 : 0.05 : 1; for i=1:21 W(i,1)=w(i)^3; W(i,2)=w(i)^2; W(i,3)=w(i); W(i,4)=1; end % Cubic Bezier transformation Matrix M=[ -1 3 -3 1; 3 -6 3 0; -3 3 0 0; 1 0 0 0;]; % Control Vertices of patch1 % P00 p10 p20 p30 p01 p11 p21 p31 p02 p12 p22 p32 p03 p13 p23 p33 patch1 = [-5, -2, 2, 5, -4, -2.5, 2.5, 4, -8.5, -4.5, 4.5, 8.5, -7, -3, 3, 7; 1, 3, 3, 1, 1, 2, 2, 1, -1, 0, 0, -1, 2, 4, 4, 2; -6, -6, -6, -6, -3, -3, -3, -3, 1, 3, 3, 1, 5, 6.5, 6.5, 5; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; % Control Vertices of patch1 CV_X=[ patch1(1,1) patch1(1,5) patch1(1,9) patch1(1,13); patch1(1,2) patch1(1,6) patch1(1,10) patch1(1,14); patch1(1,3) patch1(1,7) patch1(1,11) patch1(1,15); patch1(1,4) patch1(1,8) patch1(1,12) patch1(1,16);]; CV_Y=[ patch1(2,1) patch1(2,5) patch1(2,9) patch1(2,13); patch1(2,2) patch1(2,6) patch1(2,10) patch1(2,14); patch1(2,3) patch1(2,7) patch1(2,11) patch1(2,15); patch1(2,4) patch1(2,8) patch1(2,12) patch1(2,16);]; CV_Z=[ patch1(3,1) patch1(3,5) patch1(3,9) patch1(3,13); patch1(3,2) patch1(3,6) patch1(3,10) patch1(3,14); patch1(3,3) patch1(3,7) patch1(3,11) patch1(3,15); patch1(3,4) patch1(3,8) patch1(3,12) patch1(3,16);]; % Bezier Surfaces for i=1:21 for j=1:21 P_X(i,j)=U(i,:)*M*CV_X*M'*W(j,:)'; P_Y(i,j)=U(i,:)*M*CV_Y*M'*W(j,:)'; P_Z(i,j)=U(i,:)*M*CV_Z*M'*W(j,:)'; end end % figure lange MIN_X=-8; MAX_X=8; MIN_Y=-8; MAX_Y=8; MIN_Z=-8; MAX_Z=8; %Plot Bezier Surfaces figure(1); axis ([MIN_X, MAX_X, MIN_Y, MAX_Y, MIN_Z, MAX_Z]); title('4-1 : Bezier Surfaces (SCREW ANGLE)'); xlabel('X'); ylabel('Y'); Zlabel('Z'); hold on; for i=1:21 plot3 (P_X(:,i), P_Y(:,i), P_Z(:,i), 'k'); plot3 (P_X(i,:), P_Y(i,:), P_Z(i,:), 'k'); end for i=1:4 plot3 (CV_X(:,i), CV_Y(:,i), CV_Z(:,i), ':'); plot3 (CV_X(i,:), CV_Y(i,:), CV_Z(i,:), ':'); end hold off; figure(2); axis ([MIN_X, MAX_X, MIN_Z, MAX_Z]); title('4-1 : Bezier Surfaces (SIDE VIEW1)'); xlabel('X'); ylabel('Z'); hold on; for i=1:21 plot (P_X(:,i), P_Z(:,i), 'k'); plot (P_X(i,:), P_Z(i,:), 'k'); end for i=1:4 plot (CV_X(:,i), CV_Z(:,i), ':'); plot (CV_X(i,:), CV_Z(i,:), ':'); end hold off; figure(3); axis ([MIN_Y, MAX_Y, MIN_Z, MAX_Z]); title('4-1 : Bezier Surfaces (SIDE VIEW2)'); xlabel('Y'); ylabel('Z'); hold on; for i=1:21 plot (P_Y(:,i), P_Z(:,i), 'k'); plot (P_Y(i,:), P_Z(i,:), 'k'); end for i=1:4 plot (CV_Y(:,i), CV_Z(:,i), ':'); plot (CV_Y(i,:), CV_Z(i,:), ':'); end hold off figure(4); axis ([MIN_X, MAX_X, MIN_Y, MAX_Y]); title('4-1 : Bezier Surfaces (TOP VIEW)'); xlabel('X'); ylabel('Y'); hold on; for i=1:21 plot (P_X(:,i), P_Y(:,i), 'k'); plot (P_X(i,:), P_Y(i,:), 'k'); end for i=1:4 plot (CV_X(:,i), CV_Y(:,i), ':'); plot (CV_X(i,:), CV_Y(i,:), ':'); end hold off
  댓글 수: 1
Dominik Cech
Dominik Cech 2021년 8월 27일
Hello, can you pleas send the code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by