MATLAB CONFIGURATION 3D NANOMATERIAL MODEL
matlab function
function mat_2 clf; clear clc close figure(1); format compact h(1) = axes('Position',[0.2 0.2 0.6 0.6]); cube = [1 1 -1; -1 1 -1; -1 1 1; 1 1 1; -1 -1 1; 1 -1 1; 1 -1 -1; -1 -1 -1]; uppercube = [.6 .4 1; -.42 .4 1; -.42 .4 3; .6 .4 3; -.42 -.4 3; .6 -.4 3; .6 -.4 1; -.42 -.4 1]; % arxizei 1 - 3 - 5 -7 versolinaki1 = [-.18 .4 1; -.38 .4 1; -.38 .4 3.1; -.18 .4 3.1; -.38 -.41 3.1; -.18 -.41 3.1; -.18 -.41 1; -.38 -.41 1]; versolinaki2 = [.06 .4 1; -.12 .4 1; -.12 .4 3.1; .06 .4 3.1; -.12 -.41 3.1; .06 -.41 3.1; .06 -.41 1; -.12 -.41 1]; versolinaki3 = [.32 .4 1; .14 .4 1; .14 .4 3.1; .32 .4 3.1; .14 -.41 3.1; .32 -.41 3.1; .32 -.41 1; .14 -.41 1]; versolinaki4 = [.58 .4 1; .4 .4 1; .4 .4 3.1; .58 .4 3.1; .4 -.41 3.1; .58 -.41 3.1; .58 -.41 1; .4 -.41 1]; fac = [1 2 3 4; 4 3 5 6; 6 7 8 5; 1 2 8 7; 6 7 1 4; 2 3 5 8]; up = patch('Faces',fac,'Vertices',cube,'FaceColor',[1 1 1]); hold on; x(1)=-.42; y(1)=-.41; z(1)=1; x(2)=-.43; y(2)=-.45; z(2)=1; x(3)=-.41; y(3)=-.49; z(3)=1; x(4)=-.36; y(4)=-.53; z(4)=1; x(5)=-.3; y(5)=-.56; z(5)=1; x(6)=-.24; y(6)=-.6; z(6)=1; x(7)=-.17; y(7)=-.64; z(7)=1; x(8)=-.1; y(8)=-.67; z(8)=1; x(9)=-.04; y(9)=-.7; z(9)=1; x(10)=0; y(10)=-.71; z(10)=1; x(11)=.04; y(11)=-.7; z(11)=1; x(12)=.14; y(12)=-.67; z(12)=1; x(13)=.24; y(13)=-.64; z(13)=1; x(14)=.34; y(14)=-.6; z(14)=1; x(15)=.44; y(15)=-.56; z(15)=1; x(16)=.52; y(16)=-.53; z(16)=1; x(17)=.56; y(17)=-.49; z(17)=1; x(18)=.59; y(18)=-.45; z(18)=1; x(19)=.58; y(19)=-.41; z(19)=1; pl = patch(x,y,z,'w') cdata = [0 0 1 0 0.8; 0 1 0 0 0.8; 1 0 1 0 0.8]'; set(pl,'FaceColor',[0 0 1]) hold on patch('Faces', fac, 'Vertices', uppercube, 'faceColor', [1 1 1],... 'AlphaDataMapping','none'); hold on; p1 = patch('Faces', fac, 'Vertices', versolinaki1, 'FaceColor', 'b'); hold on; p2 = patch('Faces', fac, 'Vertices', versolinaki2, 'FaceColor', 'b'); hold on; p3 = patch('Faces', fac, 'Vertices', versolinaki3, 'FaceColor', 'b'); hold on; p4 = patch('Faces', fac, 'Vertices', versolinaki4, 'FaceColor', 'b'); %view(40,60) %{ hold on; xx(1)=-.42; yy(1)=-.4; zz(1)=3.16; xx(2)=-.42; yy(2)=.4; zz(2)=3.16; xx(3)=.6; yy(3)=.4; zz(3)=3.16; xx(4)=.6; yy(4)=-.4; zz(4)=3.16; p = patch(xx,yy,zz,'w') cdata = [0 0 1 0 0.8; 0 1 0 0 0.8; 1 0 1 0 0.8]'; set(p,'FaceColor',[1 1 1]) %} view(12,59) %view(14.5,59) %axis([-2 3 -2 2 -8.3 2.3]) %axis([-2 2 -2 2 -2.3 2.3]) % view(7,79) set(gca,'color',[1 1 1]) axis off %for i=1:340,view(i,i),drawnow,end %axis([-.5 .5 -1 1 -2.3 2.3]) %axis tight bu1=uicontrol('Style', 'pushbutton', 'String', 'Run simulation',... 'backgroundcolor',[.8 .8 .8],'fontSize',10,... 'foregroundColor',[0 0 0],... 'units','normalized',... 'units','normalized',... 'Position', [.1 .8 .3 .1],... 'callback',{@moving,versolinaki1,versolinaki2,versolinaki3,versolinaki4,x,y,z,pl,p1,p2,p3,p4,up}) %========================================= function moving(cbo,eventdata,versolinaki1,versolinaki2,versolinaki3,versolinaki4,x,y,z,pl,p1,p2,p3,p4,up) set(up,'faceColor',[.7 .7 .7]) title(['3D model',10,'Ted Aspiotis',10,'tedasjob@gmail.com']) xd1 = get(p1,'xData'); xd2 = get(p2,'xData'); xd3 = get(p3,'xData'); xd4 = get(p4,'xData'); yd1 = get(p1,'YData'); yd2 = get(p2,'YData'); yd3 = get(p3,'YData'); yd4 = get(p4,'yData'); zd1 = get(p1,'zData'); zd2 = get(p2,'zData'); zd3 = get(p3,'zData'); zd4 = get(p4,'zData'); aaa=get(pl,'yData'); alpha(.7) axis off yyy = .4; aa = -.03; view(40,70) %{ view(40,70) xa(1) = -.4 ; ya(1) = -.4; za(1) = 1; xa(2) = .4 ; ya(2) = -.4; za(2) = 1; xa(3) = .4 ; ya(3) = .4; za(3) = 1; xa(4) = -.4 ; ya(4) = .4; za(4) = 1; pla = patch(xa,ya,za,'b') %} for i=1:9 yd1(1:4,1) = yyy; yd1(31:2,2)= yyy ; yd1(1:2,4) = yyy ; yd1(3:4,5) = yyy ; yd1(1:2,6) = yyy ; yd2(1:4,1) = yyy; yd2(31:2,2)= yyy ; yd2(1:2,4) = yyy ; yd2(3:4,5) = yyy ; yd2(1:2,6) = yyy ; yd3(1:4,1) = yyy; yd3(31:2,2)= yyy ; yd3(1:2,4) = yyy ; yd3(3:4,5) = yyy ; yd3(1:2,6) = yyy ; yd4(1:4,1) = yyy; yd4(31:2,2)= yyy ; yd4(1:2,4) = yyy ; yd4(3:4,5) = yyy ; yd4(1:2,6) = yyy ; xd3 = get(p3,'xData'); yyy = yyy - .1; set(p1,'XData',xd1,'YData',yd1 ,'ZData',zd1); set(p2,'XData',xd2,'YData',yd2 ,'ZData',zd2); set(p3,'XData',xd3,'YData',yd3 ,'ZData',zd3); set(p4,'XData',xd4,'YData',yd4 ,'ZData',zd4); set(pl,'YData',aaa+.22-aa) aaa = aaa + aa; drawnow pause(1) img(i) = getframe(gcf); imwrite(img(i).cdata,['model' num2str(100+i) '.jpg']) end |