フィルターのクリア

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 Center および File ExchangeSurface 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