plotting a surface on a cylinder top face
3 views (last 30 days)
Show older comments
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');
0 Comments
Answers (1)
Chunru
on 3 Aug 2022
Edited: Chunru
on 4 Aug 2022
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);
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!