首页 > 代码库 > 无聊,绘正方体

无聊,绘正方体

clc;
clear all;
close all;

%% 画长方体% --------------xy底面---------------
x = -10:1:10;
y = x;
[x,y]=meshgrid(x,y);
z = -10*ones(size(x));
p1 = surf(x,y,z);
shading interp
alpha(0.6)
hold on
% --------------xz侧面---------------
x = -10:1:10;
z = x;
[x,z]=meshgrid(x,z);
y = -10*ones(size(x));
surf(x,y,z);
shading interp
alpha(0.6)
% --------------xz侧面---------------
x = -10:1:10;
z = x;
[x,z]=meshgrid(x,z);
y = 10*ones(size(x));
surf(x,y,z);
shading interp
alpha(0.6)
% --------------yz侧面---------------
y = -10:1:10;
z = y;
[y,z]=meshgrid(y,z);
x = 10*ones(size(y));
surf(x,y,z);
shading interp
alpha(0.6)
% --------------yz侧面---------------
y = -10:1:10;
z = y;
[y,z]=meshgrid(y,z);
x = -10*ones(size(y));
surf(x,y,z);
shading interp
alpha(0.6)
%-----------波面----------------------------------
x = -10:1:10;
y = x;
[x,y]=meshgrid(x,y);
z = ones(size(x));
p1 = surf(x,y,z);
set(p1,‘FaceColor‘,‘b‘);
shading interp
alpha(0.6)
hold on
%-----------鱼粪----------------------------------
% rand(‘seed‘,0);
x = 10*(2*rand(1,4) - 1);
y = 10*(2*rand(1,4) - 1);
z = rand(1,4) - 9;
plot3(x,y,z,‘kh‘,‘MarkerFaceColor‘,‘k‘,‘markersize‘,12);
%-----------鱼料---------------------------------
x = 10*(2*rand(1,4) - 1);
y = 10*(2*rand(1,4) - 1);
dx = rand;
dy = rand;
z = rand(1,4)-1 ;
dz = rand;
plot3([x,x+dx],[y,y+dy],[z,z+dz],‘mo‘,‘MarkerFaceColor‘,‘m‘,‘markersize‘,14);
%-----------------------小鱼-------------------------
xx = 10*(2*rand - 1);
yy = 10*(2*rand - 1);
zz =-5*rand ;
p2 =plot3(xx,yy,zz,‘ro‘,‘MarkerFaceColor‘,‘r‘,‘markersize‘,22);
tem = 1000;
for i= 1:1000
dx =unifrnd(-1,1);
dy = unifrnd(-1,1);
dz = unifrnd(-1,1);
temz1 = -9;
temz2 = -1;
temx1 = -9;
temx2 = 9;
temy1 = -9;
temy2 = 9;
if ( zz > temz1)&& (zz < temz2)
if ( xx> temx1)&& (xx < temx2)
if ( yy > temy1)&&(yy < temy2)
xx = xx + dx;
yy = yy + dy;
zz = zz + dz;
set(p2,‘xdata‘,xx,‘ydata‘,yy,‘zdata‘,zz);
end
end
elseif ( zz >temz1)&& (zz < temz2) &&( xx>temx1)&& (xx < temx2)
xx = xx +dx;
yy = yy - dy;
zz = zz +dz;
set(p2,‘xdata‘,xx,‘ydata‘,yy,‘zdata‘,zz);
elseif ( zz >temz1)&& (zz < temz2) &&( yy >temy1)&& (yy < temy2)
xx = xx -dx;
yy = yy + dy;
zz = zz +dz;
set(p2,‘xdata‘,xx,‘ydata‘,yy,‘zdata‘,zz);
elseif ( xx>temx1)&& (xx < temx2)&&( yy >temy1)&& (yy< temy2)
xx = xx +dx;
yy = yy + dy;
zz = zz -dz;
set(p2,‘xdata‘,xx,‘ydata‘,yy,‘zdata‘,zz);
else
continue
end
tem = tem -1;
pause(0.1)
drawnow

end
% while
% [y,fs] =audioread(‘2865a93400.mp3‘);
% sound(y, fs);
% end

无聊,绘正方体