PLANE1_.m
- % plane_ same as List_B4.
- % Plots a wire frame airplane.
- % Copyright S. Nakamura
- set(gcf, 'NumberTitle','off','Name', 'Figure B.3; plane_ ')
- % scrsz = get(0,'ScreenSize');
- % set(gcf,'Position',[30 80 scrsz(3)-280 scrsz(4)-280])
- clc
- clear all, clf
- mov1 = avifile('airplanh.avi');
- for hhh = 0:0.2:50
- dth=pi/16;
- fuselen=6;
- thf=pi:-dth:pi/2;
- xa = 0:0.5:fuselen;
- hyq_x = 0;
- hyq_y = 0;
- hyq_z = 0;
- xt=fuselen+0.25:0.25:fuselen+2;
- dxt = 1.4/(length(xt)-0) ;
- yt = -1+dxt:dxt :0.4;
- length(yt);
- xft=[cos(thf),xa, xt] ;
-
- yft=[sin(thf)- 0.3*sin(2*thf).^4, ones(size(xa)), ones(size(yt))] ;
- xfb=[cos(thf),xa,xt] ;
- yfb=[-sin(thf),-ones(size(xa)),yt ] ;
- k=length([thf, xa]);
- yfb(k)=( yfb(k-1)+yfb(k+1))/2;
- xc =(xfb+xft)/2 ;
- yc = (yfb+yft)/2;
- L=length(xc);
- for i=1:L
- if xc(i)<0
- yc(i)=0;
- end
- end
- % plot(xfb,yfb,'y', xft,yft,'y', xc, yc,':')
- %
- % axis([-2 8 -6 6])
- % pause
- a=0.5;
- b=0.5;
- dth=pi/8;
- th=0:dth:2*pi;
- jmax=length(th);
- xr=cos(th);
- yr=sin(th);
- L=length(xc);
- for i=1:L
- a = (yft(i) -yc(i))/(-yfb(i) + yc(i));
- b = (-yfb(i) +yc(i));
- for j=1:jmax
- y(i,j)=yr(j)*b+yc(i);
- if th(j)<pi y(i,j)=yr(j)*b*a + yc(i); end
- x(i,j)=xr(j)*b;
- z(i,j)=xc(i);
- end
- end
- opengl neverselect
- [xw,yw,zw] = wing_;
- F = 1.7;
- xw=F*xw; yw=F*yw; zw=F*zw;
- [x1,y1,z1] = rotz_(xw,yw,zw,-90);
- [x2,y2,z2] = rotx_(xw,yw,zw,180);
- [x2,y2,z2] = rotz_(x2,y2,z2,-270);
- aa = -2.8;
- z = z+aa;
- x3 = x1+2+aa;
- y3 = y1-0.5;
- z3 = z1+0.7;
- x4 = x2+2+aa;
- y4 = y2+0.5;
- z4 = z2+0.7;
- x5 = 0.8*x1+6.6+aa;
- z5 = 0.5*z1;
- y5 = -0.3*y1+1.2;
- x6 = 0.7*x1+6.6+aa;
- y6 = 0.3*y1-0.7;
- z6 = 0.9*z1+0.7;
- x7 = 0.7*x2+6.6+aa;
- y7 = 0.3*y2+0.7;
- z7 = 0.9*z2+0.7;
- % 侧倾角变换
- [x3,y3,z3]=rotx_(x3,y3,z3,hhh);
- [x4,y4,z4]=rotx_(x4,y4,z4,hhh);
- [x5,z5,y5]=rotx_(x5,z5,y5,hhh);
- [x6,y6,z6]=rotx_(x6,y6,z6,hhh);
- [x7,y7,z7]=rotx_(x7,y7,z7,hhh);
- [z,x,y] = rotx_(z,x,y,hhh);
- % 俯仰角变换
- [x3,y3,z3]=roty_(x3,y3,z3,hhh);
- [x4,y4,z4]=roty_(x4,y4,z4,hhh);
- [x5,z5,y5]=roty_(x5,z5,y5,hhh);
- [x6,y6,z6]=roty_(x6,y6,z6,hhh);
- [x7,y7,z7]=roty_(x7,y7,z7,hhh);
- [z,x,y] = roty_(z,x,y,hhh);
- % 航向角变换
- [x3,y3,z3]=rotz_(x3,y3,z3,hhh);
- [x4,y4,z4]=rotz_(x4,y4,z4,hhh);
- [x5,z5,y5]=rotz_(x5,z5,y5,hhh);
- [x6,y6,z6]=rotz_(x6,y6,z6,hhh);
- [x7,y7,z7]=rotz_(x7,y7,z7,hhh);
- [z,x,y] = rotz_(z,x,y,hhh);
- clf
- subplot(221)
- surface(z+hyq_x,x+hyq_y,y+hyq_z)
- axis([-16 16 -16 16 -16 16])
- hold on
- surfc(z+hyq_x,x+hyq_y,y+hyq_z)
- surface(x3+hyq_x,y3+hyq_y,z3+hyq_z);
- surface(x4+hyq_x,y4+hyq_y,z4+hyq_z);
- surface(x5+hyq_x,z5+hyq_y,y5+hyq_z)
- surface(x6+hyq_x,y6+hyq_y,z6+hyq_z);
- surface(x7+hyq_x,y7+hyq_y,z7+hyq_z);
- grid
- subplot(222)
- surface(z+hyq_x,x+hyq_y,y+hyq_z)
- axis([-16 16 -16 16 -16 16])
- hold on
- surfc(z+hyq_x,x+hyq_y,y+hyq_z)
- surface(x3+hyq_x,y3+hyq_y,z3+hyq_z);
- surface(x4+hyq_x,y4+hyq_y,z4+hyq_z);
- surface(x5+hyq_x,z5+hyq_y,y5+hyq_z)
- surface(x6+hyq_x,y6+hyq_y,z6+hyq_z);
- surface(x7+hyq_x,y7+hyq_y,z7+hyq_z);
- view([0 0])
- grid
- subplot(223)
- surface(z+hyq_x,x+hyq_y,y+hyq_z)
- axis([-16 16 -16 16 -16 16])
- hold on
- surfc(z+hyq_x,x+hyq_y,y+hyq_z)
- surface(x3+hyq_x,y3+hyq_y,z3+hyq_z);
- surface(x4+hyq_x,y4+hyq_y,z4+hyq_z);
- surface(x5+hyq_x,z5+hyq_y,y5+hyq_z)
- surface(x6+hyq_x,y6+hyq_y,z6+hyq_z);
- surface(x7+hyq_x,y7+hyq_y,z7+hyq_z);
- view([0 90])
- grid
- subplot(224)
- surface(z+hyq_x,x+hyq_y,y+hyq_z)
- axis([-16 16 -16 16 -16 16])
- hold on
- surfc(z+hyq_x,x+hyq_y,y+hyq_z)
- surface(x3+hyq_x,y3+hyq_y,z3+hyq_z);
- surface(x4+hyq_x,y4+hyq_y,z4+hyq_z);
- surface(x5+hyq_x,z5+hyq_y,y5+hyq_z)
- surface(x6+hyq_x,y6+hyq_y,z6+hyq_z);
- surface(x7+hyq_x,y7+hyq_y,z7+hyq_z);
- view([90 0])
- grid
- caxis([-3,1])
- title('Commuter Airplane')
- caxis([-2, 2])
- colormap(hsv)
- F = getframe(gcf);
- mov1 = addframe(mov1,F);
- end
- mov1 = close(mov1);
复制代码 |