필터 지우기
필터 지우기

plotting a surface on a cylinder top face

조회 수: 3 (최근 30일)
Ilan Shklarsh
Ilan Shklarsh 2022년 8월 2일
댓글: Chunru 2022년 8월 4일
Im triying to plot a surface on the top face of a cylinder using surface command, when I ran the code I get the surface on the squre that block the the face and not only on the face- my code:
theta =0:0.01*pi:2*pi; r=0.8;
x=r*cos(theta); y=r*sin(theta); f=(1:1:4);
V=[x' y'];
Patch=patch('Faces',f,'Vertices',V,'FaceColor', [171 104 87]./255);
C=Patch.FaceColor;
xd = get(Patch, 'XData')';
yd = get(Patch, 'YData')';
z0=zeros(1,length(xd));
zf=0.1*ones(1,length(xd));
Vx_ud(:,1)=xd; Vx_ud(:,2)=xd; Vy_ud(:,1)=yd; Vy_ud(:,2)=yd;
Vz_ud(:,1)=z0; Vz_ud(:,2)=zf;
ud=patch(Vx_ud,Vy_ud,Vz_ud,C);
for i=1:length(xd)-1
Vx_s(:,i)=[xd(i) xd(i+1) xd(i+1) xd(i)];
Vy_s(:,i)=[yd(i) yd(i+1) yd(i+1) yd(i)];
Vz_s(:,i)=[0 0 0.1 0.1];
end
Vx_s(:,length(xd))=[xd(end) xd(1) xd(1) xd(end)];
Vy_s(:,length(xd))=[yd(end) yd(1) yd(1) yd(end)];
Vz_s(:,length(xd))=[0 0 0.1 0.1];
s=patch(Vx_s,Vy_s,Vz_s,C,'EdgeColor','none');
th_DPatch=[ud, s];
I=imread('road.jpg');
Z=0.1*ones(201);
Face=surface(x,y,Z,EdgeColor="none");
set(Face,'CData',I,'FaceColor','texturemap');

답변 (1개)

Chunru
Chunru 2022년 8월 3일
편집: Chunru 2022년 8월 4일
theta =0:0.01*pi:2*pi; r=0.8;
x=r*cos(theta); y=r*sin(theta); z=zeros(size(x));
% simple patch for base
p_base =patch(x, y, z, [171 104 87]./255); hold on
% cylinder
[xc, yc, zc] = cylinder(r, length(theta)-1);
cc = repmat(reshape([171 104 87]./255, 1, 1, 3), size(xc));
surf(xc, yc, zc*0.1, cc, 'EdgeColor', 'none'); view(3)
% simple patch for base
p_top =patch(x, y, z+0.1, [171 104 87]./255);
  댓글 수: 2
Ilan Shklarsh
Ilan Shklarsh 2022년 8월 3일
Hello
May intantion is to use surface only on the top circle in round shap and not as a ractangle.
Do you know how to do that?
Chunru
Chunru 2022년 8월 4일
See the update.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by