%画由长方体组成的各种不规则形体
clear;clc
%画一个小正方体
x=10;y=10;z=10;%角点
l=10;w=10;h=10;%长,宽,高
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
camlight
grid on;
%画长棱柱1
for x = 5:2:95
for y = 5:2:95
if x+y==60
z = 30
l=5;w=5;h=5
hold on;
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
end
end
end
%画长棱柱2
for x = 5:1:95
for y = 5:1:95
if x-+y==60
z = 20
l=10;w=10;h=10
hold on;
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
end
end
end
%画球
hold on;
[m,n,k]=sphere(20)
for i =1:1:20
for j = 1:1:20
x=m(i,j)*20+70
y=n(i,j)*20+70
z=k(i,j)*20+70
l=8;w=8;h=8
hold on;
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
end
end
%画随机图形
for x = 5:10:50
for y = 50:10:95
z = 40
l = rand(1,1)*5
w = rand(1,1)*5
h = rand(1,1)*5 %长宽高随机
hold on;
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
end
end
%画圆
[m,n,k]=sphere(20)
for i =1:1:20
for j = 1:1:20
if (k(i,j)*20+40<42) &&(k(i,j)*20+40>38)
x=m(i,j)*20+30
y=n(i,j)*20+60
z=k(i,j)*20+40
l=6;w=6;h=3
hold on;
[a,b,c]=meshgrid([0 1]);
p=alphaShape(l*a(:)-(l-x),w*b(:)-(w-y),h*c(:)-(0-z));
plot(p,'edgecolor','none')
xlabel('x');ylabel('y');zlabel('z');
end
end
end
axis([0,100,0,100,0,100]);
结果: