怎样用matlab画水平实心圆柱体,已知圆柱体的半径和高度。(悬赏值不够了,见谅)
clear all
r=1;%圆柱半径
n=100;%设置多少个边逼近圆
h=5;%圆柱高
[x,y,z]=cylinder(r,n);%生成标准的100个面的圆柱数据,半径为r,高为1,底面圆心0,0;
z1=[z(1,:);z(2,:)+h-1];%圆柱高增高,变为高h
%为变成实心封顶添加数据
z2=[z(1,:);z1;z1(2,:)];
x2=[zeros(1,n+1);x;zeros(1,n+1)];
y2=[zeros(1,n+1);y;zeros(1,n+1)];
z3=[z1(1,:);z1(1,:)];
x3=[x(1,:);x(1,:)];
y3=[y(1,:);y(1,:)];
z4=[z1(2,:);z1(2,:)];
z5=z2([1,2],:);
x5=x2([1,2],:);
y5=y2([1,2],:);
z6=z2([3,4],:);
figure(1)
mesh(x2,z2,y2)
map=jet(16);
cl=12;%可设置16种颜色(1-16)
map1=map(cl,:);
colormap(map1)
alpha(0.6)%调节透明度(0-1)
axis equal
figure(2)
surf(x2,z2,y2,'LineStyle','none')
map=jet(16);
cl=4;%可设置16种颜色(1-16)
map1=map(cl,:);
colormap(map1)
hold on
surf(x3,z3,y3)
surf(x3,z4,y3)
alpha(.7)%调节透明度(0-1)
hold off
axis equal
figure(3)
surf(x,z1,y)
map=jet(16);
cl=13;%可设置8种颜色(1-16)
map1=map(cl,:);
colormap(map1)
hold on
surf(x5,z5,y5,'LineStyle','none')
surf(x5,z6,y5,'LineStyle','none')
alpha(.9)%调节透明度(0-1)
hold off
axis equal