volume.txt

来自「it is about the matlab volume code.」· 文本 代码 · 共 55 行

TXT
55
字号
function boxplot3(x0,y0,z0,Lx,Ly,Lz) 
%(x0,y0,z0)是第一个顶点的位置; (Lx,Ly,Lz)是长方体的长宽高. 
x=[x0 x0 x0 x0 x0+Lx x0+Lx x0+Lx x0+Lx]; 
y=[y0 y0 y0+Ly y0+Ly y0 y0 y0+Ly y0+Ly]; 
z=[z0 z0+Lz z0+Lz z0 z0 z0+Lz z0+Lz z0]; 
index=zeros(6,5); 
index(1,:)=[1 2 3 4 1]; 
index(2,:)=[5 6 7 8 5]; 
index(3,:)=[1 2 6 5 1]; 
index(4,:)=[4 3 7 8 4]; 
index(5,:)=[2 6 7 3 2]; 
index(6,:)=[1 5 8 4 1]; 
for k=1:6 
plot3(x(index(k,:)),y(index(k,:)),z(index(k,:))) 
hold on 
end 
保存为 boxplot3.m 文件后 
在窗口中,调用 

boxplot3(1,2,3,5,5,5) 

就可得到边长为5的正方体.. (1,2,3)为第一个顶点的位置 

补充程序: 
编写两个M文件,并保存 
(1) 
function [xx,yy,zz,l]=planarsurface(p0,p1,p2) 
v=p1-p0; 
w=p2-p0; 
s=0:0.2:1; 
l=length(s); 
[s,t]=meshgrid(s,s); 
xx=p0(1)+s*v(1)+t*w(1); 
yy=p0(2)+s*v(2)+t*w(2); 
zz=p0(3)+s*v(3)+t*w(3); 

(2)function boxsurface(p0,l) 
[x,y,z]=planarsurface(p0,p0+[0 0 l(3)],p0+[0 l(2) 0]); 
surf(x,y,z) 
hold on 
[x,y,z]=planarsurface(p0+[l(1) 0 0],p0+[l(1) 0 l(3)],p0+[l(1) l(2) 0]); 
surf(x,y,z) 
[x,y,z]=planarsurface(p0,p0+[0 0 l(3)],p0+[l(1) 0 0]); 
surf(x,y,z) 
[x,y,z]=planarsurface(p0+[0 l(2) 0],p0+[0 l(2) l(3)],p0+[l(1) l(2) 0]); 
surf(x,y,z) 
[x,y,z]=planarsurface(p0,p0+[l(1) 0 0],p0+[0 l(2) 0]); 
surf(x,y,z) 
[x,y,z]=planarsurface(p0+[0 0 l(3)],p0+[l(1) 0 l(3)],p0+[0 l(2) l(3)]); 
surf(x,y,z) 
axis equal 
axis off 

运行: boxsurface([1 1 1],[2 2 2]) 
%[1 1 1]表示初始位置.[2 2 2]: 边长 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?