3D Graphics

The world we live in is three dimensional (3D) and the computer screen that we use in the labs is two dimensional (2D). There have been several attempts to investigate alternative methods to represent phyical situations on the flat screen of the computer screen.

Let's explore what the MATLAB

commands will do for us.

So we'll begin with some data that's easy to generate:

x = [0: pi/4: 6*pi];

y = [-pi/2: pi/16: pi/2];

z = y' * cos(x);

% why did i use y' above?

mesh(z)

title('Mesh Surface: f(x,y) = y cos(x)')

figure

[X,Y] = meshgrid(-8:.5:8); %create a matrix of (X,Y) from vector

R = sqrt(X.^2 + Y.^2) + eps; % sinc function sin(r)/r

Z = sin(R)./R;

mesh(X,Y,Z)

figure

mesh(x,y,z)

title('Mesh Surface: f(x,y) = y cos(x)')

xlabel('x'),ylabel('y'),zlabel('z')

figure

surf(z)

title('Shade Surface: f(x,y) = y cos(x)')

figure

contour(z)

title('Contour: f(x,y) = y cos(x)')

xlabel('x'), ylabel('y')

figure

meshc(z)

title('Mesh Surface with Contour: f(x,y) = y cos(x)

xlabel('x'), ylabel('y'), zlabel('z')
Within the MATLAB environment, it will be useful to explore

help hold % useful to plot another curve within current figure

[x,y,z] = peaks % predefined data set

contour (x,y,z,20,'k')

hold on

pcolor(x,y,z) % pseudocolor (checkerboard) plot

shading interp % default value is "faceted"

rotate3d on % your mouse can change azimuth and elevation - patience

figure

[c,h] = contour(peaks), clabel(c,h), colorbar % get picture with contours labeled and a color bar

figure

[x,y,z] = peaks % predefined data set

mesh(x,y,z)

view(-37.5,30)

view(0,0)

view(-90,0)

view(-37.5,10)