Professional Documents
Culture Documents
Bijan Mobasseri
Department Of Electrical and Computer Engineering Villanova University
1 / 43
Objectives
2 / 43
A 3-D plot can be interpreted as heights above the ground plane. These heights are evaluated at some predened grid points
3 / 43
The groundplane must rst be represented by a grid This grid in reality consists of two matrices: x and y
4 / 43
Lets say we want to sample the ground plane by a grid of points; x=-8:0.5:8; y=x; [X,Y]=meshgrid(x,y) X and Y are now matrices, as shown on the next slide.
5 / 43
6 / 43
Another look
8 / 43
There are a number of built-in functions in MATLAB that we can just use In the 2D case, we have humps
Example: plot(humps)
9 / 43
Use of mesh(Z) plots Z vs. index positions To plot Z vs. actual units of X and Y:
[X,Y]=meshgrid(-3:0.2:3) Z=peaks(X,Y); mesh(X,Y,Z)
10 / 43
In mesh(X,Y,Z), X and Y must come out of meshgrid. This is wrong x=-3:0.1:3 y=x; Z=peaks(x,y) mesh(Z) This is right x=-3:0.1:3 y=x; [X,Y]=meshgrid(x,y) Z=peaks(X,Y) mesh(Z)
11 / 43
Contour Plot
Contours are slices of constant height that are then projected onto the ground plane In its simplest form meshc(Z) does the job
12 / 43
Curtain Plot
You can put your plot on a pedestal by using meshz(Z)
13 / 43
Waterfall Plots
An interesting effect can be generated by just plotting the rows of the Z matrix using
waterfall(X,Y,Z)
14 / 43
mesh generates discrete plots. To generate surfaces with solid shading, surf and its variations are used These variations are
surf surfl surfc
15 / 43
Using surf
Usage:
surf(X,Y,Z,C)
(X,Y) is generated via meshgrid command and Z is the height of the function. Z-to-color mapping is done according to the entries into "colormap" via C (more on that later) If surf(Z) is used, color is proportional to height Z.
16 / 43
17 / 43
Shading control
Shading can be applied to surface objects to enhance viewing. There are three types of shading, 1) at, 2) faceted and 3) interpolated In at shading, surface patches are shaded in constant colors. In interpolated shading, surface patches have a color gradient proportional to the z-value. Faceted shading is the same as at shading except for the black mesh lines.
18 / 43
Flat shading
Faceted shading
Interpolated shading
2D Contour Example
Here you slice the surface at 10 different heights and project the contours on the ground plane. Each contour represent a xed height.
22 / 43
3D contours
contour3(x,y,z,20)
23 / 43
Filled contours
contourf(x,y,z,10)
24 / 43
25 / 43
Controlling Viewpoint
Viewpoint is controlled by two angles: azimuth and elevation Azimuth is rotation around the Z-axis Elevation is rising above the ground plane
26 / 43
Default Viewpoints
In MATLAB, default viewpoints are az=-37.5 and el=30 degrees Zero degrees azimuth is like looking up the rst column of the Z matrix. Zero degrees of elevation is like looking "edge on" the Z matrix
27 / 43
Increasingly negative azimuth is like holding the object in front of you while rotating it counterclockwise. Look at the next slide for a demonstration
28 / 43
32 / 43
Positive elevation angle means rising above the object. Elevation of +90 degrees means being directly overhead and looking down Check this out yourself
33 / 43
View command
Controlling view point is done through the view command Display your 3D plot then use view([-35,60])
34 / 43
If you have a 3D-display but dont know what your viewpoint is, use the following: [az,el]=view MATLAB returns azimuth and elevation view points of the current plot
35 / 43
Display your 3D plot then type rotate3d in the command window Now bring the gure window to the fore, click on it, hold down the mouse button and then move it around
36 / 43
You can shine light on a surface from a desired direction Shading is based on a combination of diffuse, specular and ambient lighting models Usage:
surfl(X,Y,Z,S) S=lighting direction=[az,el]
37 / 43
To save space, we can divide the paper into a grid and place a separate plot inside each grid
38 / 43
Subplot command
subplot(mnp) divides the page into m(rows)n(columns) tiles then selects the pth tile for plotting
39 / 43
40 / 43
Cylinder
cylinder(radius,pnts) generates a cylinder of radius using N points along each axis
41 / 43
Generalized cylinder
A generalized cylinder is a solid whose axis is a 3-D space curve and a variable radius cross section.
42 / 43
43 / 43