我试着编写了一个,即把正方体由每个线段拼接起来。
-
- clc
- clear
- a=2;
- b=4;
- x1=[0 a a 0];
- y1=[0 0 a a];
- z1=[0 0 0 0];
- z2=[a a a a];
- subplot(121)
- hold on
- plot3([x1,x1(1)],[y1,y1(1)],[z1,z1(1)])
- plot3([x1,x1(1)],[y1,y1(1)],[z2,z2(1)])
- for i=1:length(x1)
- plot3([x1(i),x1(i)],[y1(i),y1(i)],[z1(i),z2(i)])
- end
- view(30,30)
- axis equal
- hold off
- %%%%%%%%%%%%%%%%%%%%%%%%%%%
- x2=[0:a/(b-1):a,a*ones(1,b-2),a:a/(1-b):0,zeros(1,b-2)];
- zh=a:a/(1-b):0;
- y2=[zeros(1,b-1),0:a/(b-1):a,a*ones(1,b-2),zh(1:3)];
- zz1=zeros(1,length(x2));
- zz2=a*ones(1,length(x2));
- subplot(122)
- hold on
- plot3(x2,y2,zz1,'.')
- plot3(x2,y2,zz2,'.')
- plot3([x2,x2(1)],[y2,y2(1)],[zz1,zz1(1)],'r')
- plot3([x2,x2(1)],[y2,y2(1)],[zz2,zz2(1)],'r')
- zh=0:a/(b-1):a;
- ind=[1 4 7 10];
- for i=1:4
- plot3([x2(ind(i)),x2(ind(i))],[y2(ind(i)),y2(ind(i))],[zh(1),zh(4)],'r')
- plot3([x2(ind(i)),x2(ind(i))],[y2(ind(i)),y2(ind(i))],zh(2:3),'.')
- end
- view(30,30)
- axis equal
- hold off
复制代码 |