plotting a surface on a cylinder top face

3 次查看(过去 30 天)
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?

请先登录,再进行评论。

类别

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