how to plot an airplane in matlab

Matlab provides extensive functionality to create 2D and 3D plots for data visualization. Plotting an airplane can also be done using the provided functionality. Here is an example of plotting an airplane in Matlab 3D space:

main.m
% Define the body
[x,y,z] = cylinder([0.3 0.3],30);
z(2,:) = 2; z(1,1:31) = [0.5 0.7 0.9 1 0.9 0.7 0.5 0.3 0 0.3 0.5 ...
    0.7 0.9 1 0.9 0.7 0.5 0.3 0 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 ...
    0.3 0.3 0.3 0.3];
surf(x,y,z,'EdgeColor','none')

% Define the wings
[x,y,z] = cylinder([0.1 0],4);
z(2,:) = 12; z(1,:) = 15;
y(2,:) = -1;
y(1,:) = -5;
surf(x+11.5,y,z,'EdgeColor','none')
surf(x-11.5,y,z,'EdgeColor','none')

% Define the tail fin
[x,y,z] = cylinder([0.05 0.1],3);
z(2,:) = 3; z(1,1:4) = [2.6 2.8 2.9 3];
y(2,:) = 2; y(1,1:4) = [1.8 1.8 2 2];
surf(x,y+3,z,'EdgeColor','none')

% Define the nose
[x,y,z] = sphere(30);
x = x*0.2;y = y*0.2;z = z*0.15;
surf(x,y+0.1,z,'EdgeColor','none')

% Set the axis limits
xlim([-15 15]), ylim([-6 6]), zlim([-5 15])
764 chars
29 lines

This code will generate a 3D plot of an airplane which can be further adjusted according to the particular use-case.

related categories

gistlibby LogSnag