Download presentation
Presentation is loading. Please wait.
Published byElinor Green Modified over 9 years ago
1
1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99
2
1999 BG Mobasseri2 8/29/2015 3-D PLOTTING There are numerous ways to display a function in 3-D in black and white as well as color One way to interpret 3D data is a series of points in space given by (x,y,z) coordinates The direct extension of the 2-D plot function, plot(x,y), to 3-D is plot3(x,y,z)
3
1999 BG Mobasseri3 8/29/2015 PLOTTING A CORKSCREW How would you model a corkscrew? Corkscrew, or spiral, is the 3-D equivalent of a spiral It goes around a circle but it also rises from the ground plane. So, what is its equation?
4
1999 BG Mobasseri4 8/29/2015 3-D EQUATION A circle can be parametrically described by –x=cos(t) –y=sin(t) To make it rise from the ground plane, let z=t and run t from 0 to 10*pi.
5
1999 BG Mobasseri5 8/29/2015 Try it!
6
1999 BG Mobasseri6 8/29/2015 Try it! Another interesting plot is the same as corkscrew but you are going up around a cone rather than a cylinder. Can you write the code?
7
1999 BG Mobasseri7 8/29/2015 DISPLAYING A FUNCTION AS A SET OF HEIGHTS A 3-D plot can be interpreted as heights above the ground plane. These heights are evaluated at some predefined grid points
8
1999 BG Mobasseri8 8/29/2015 mesh and meshgrid To plot a function in 3D we need to understand mesh and meshgrid. meshgrid samples the ground plane into a grid of points –x=- 8:0.5:8; –y=x; –[x,y]=meshgrid(x,y) x and y are now matrices mesh evaluates the function over the grid
9
1999 BG Mobasseri9 8/29/2015 EXMAPLE: SOMBRERO Sombrero, looking like a Mexican hat, is defined by sin(r)/r. r is the distance of a point (x,y) to the origin, i.e. –r 2 =x 2 +y 2 r
10
1999 BG Mobasseri10 8/29/2015 Try it!
11
1999 BG Mobasseri11 8/29/2015 SOMBRERO
12
1999 BG Mobasseri12 8/29/2015 GENERATING TRUE AXIS UNITS Use of mesh (z) plots z vs. index positions not actual x or y values To plot z vs. actual units of x and y, just use x and y in the mesh command like –mesh(x,y,z) Note that x and y can come from the output of meshgrid
13
1999 BG Mobasseri13 8/29/2015 Try it! MATLAB has a built-in function called peaks How can you make the plot look smoother?
14
1999 BG Mobasseri14 8/29/2015 What to do in the following slides Each slide shows a variation of the mesh command on a function z Since you already have z defined for both sombrero and peaks, for each slide duplicate the command shown and see the result for yourself
15
1999 BG Mobasseri15 8/29/2015 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
16
1999 BG Mobasseri16 8/29/2015 CURTAIN PLOT You can put your plot on a ‘pedestal’ by using meshz (Z)
17
1999 BG Mobasseri17 8/29/2015 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 z x y el az
18
1999 BG Mobasseri18 8/29/2015 DEFAULT VIEWPOINTS In MATLAB, default viewpoints are az=- 37.5 and el=30 degrees Zero degrees azimuth is like looking up the x- axis shown in the previous slide. 90 degrees of elevation is like looking directly down on the the surface
19
1999 BG Mobasseri19 8/29/2015 Working with viewpoint The best way to understand viewpoint is to play around To understand the effect of elevation, fix your azimuth at 0 then change your elevation: –view(0,10),view(0,30),view(0,60) Or fix your elevation at 30 degrees and change your azimuth –Compare view(30,60) with view(-20, 60)
20
1999 BG Mobasseri20 8/29/2015 INTERPRETING SIGNS OF VIEWPOINT ANGLES Increasingly negative azimuth angle corresponds to holding the object in front of you and rotating it counterclockwise. Equivalently, it corresponds to keeping the object stationary and moving around it clockwise Positive elevation angle mean rising above the object. Elevation of +90 degrees means being directly overhead and looking down
21
1999 BG Mobasseri21 8/29/2015 Homework#1 For the following function –do a mesh plot then title and label all axis –visually find out how deep the hole is? –what is happening inside(looking underneath)? –generate 3D contours(30 of them) –Write a procedure that would cap the plot to 70% of its peak value then plot it. Your plot should show a flat top
22
1999 BG Mobasseri22 8/29/2015 GENERATING SHADED PLOTS mesh generates wiremesh plots(can see lines) To generate surfaces with solid shading, surf and its variations are used These variations are –surf –surfl (this is surf followed by lower case L) –surfc
23
1999 BG Mobasseri23 8/29/2015 Using surf Usage: –surf(x,y,z,C) (x,y) is generated via meshgrid and z is the height of the function. z-to-color mapping is done according to the entries into “colormap” via C. More on this later If surf(z) is used, color is proportional to height z.
24
1999 BG Mobasseri24 8/29/2015 Plotting peaks using surf Generate the peaks function in the range (-4 to 4) in increments of.5 Then use –surf(x,y,z) For comparison, use mesh and display it in a second window
25
1999 BG Mobasseri25 8/29/2015 Try it! Look closely and see if you can tell the difference between surf and mesh
26
1999 BG Mobasseri26 8/29/2015 mesh vs. surf Display mesh and surf side-by-side
27
1999 BG Mobasseri27 8/29/2015 SOLID SHADING- shading To plot solid looking shapes, as opposed to wiremeshes, shading command comes in –shading flat –shading faceted –shading interp
28
1999 BG Mobasseri28 8/29/2015 Try it! Display one of your favorite 3D shapes you have done so far and in the command window type and observe –shading flat –shading faceted –shading interp
29
1999 BG Mobasseri29 8/29/2015 FLAT vs. FACETED vs. INTERPOLATED SHADING Flat shading assigns constant colors to surface patches Faceted shading assigns constant colors but also shows the wiremeshes Interpolated shading assigns colors proportional to height of the function
30
1999 BG Mobasseri30 8/29/2015 3D CONTOURS contour projects 3D contours of a surface onto the ground plane contour3 shows the true 3D contours Usages are –contour3(x,y,z,N) This command generates N contours of the function Z. Default is N=10
31
1999 BG Mobasseri31 8/29/2015 Try it! Display the peaks function over x and y ranging over - 5 to 5 in increments of 0.1 Then do the following –Display 50 2D contours using contour –Display 50 3D contours using contour3d
32
1999 BG Mobasseri32 8/29/2015 FEW EXAMPLES 20 contours
33
1999 BG Mobasseri33 8/29/2015 Can you get this? Hint: contour displays its plots on the z=0 plane
34
1999 BG Mobasseri34 8/29/2015 CONTROLLING LIGHTING DIRECTION-surfl 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] where az and el are azimuth and elevation angles previously defined
35
1999 BG Mobasseri35 8/29/2015 Lighting example Keep changing the s parameter and watch
36
1999 BG Mobasseri36 8/29/2015 WATERFALL PLOTS An interesting effect can be generated by just plotting the rows of the Z matrix using –waterfall(x,y,z)
37
1999 BG Mobasseri37 8/29/2015 Putting several plots on a single page subplot(mnp) divides the page into m(rows)xn(columns) tiles then selects the pth tile for the current plot This tile would be Referred to by subplot (235)
38
1999 BG Mobasseri38 8/29/2015 Seeing subplot at work Let’s say we want to partition the page into 3x2=6 tiles. Simply type the following in the command window and see what happens –subplot(232) –subplot(235) –subplot(233) –subplot(234) –subplot(236)
39
1999 BG Mobasseri39 8/29/2015 Homework #2: placing 4 plots on a page Let’s say we have 4 plots (choose your own) and want to arrange them on paper in the following styles –Across the page in one row –Vertical in one column –In a matrix, 2x2 tiles on a page
40
1999 BG Mobasseri40 8/29/2015 Special surfaces: cylinder and sphere sphere(n) will generate a plot of unit sphere using (n+1)^2 points. Another usage is –[x,y,z]=sphere(25); –surf(x,y,z) Similarly, we can generate a cylinder of radius 1 using cylinder.
41
1999 BG Mobasseri41 8/29/2015 Generalized cylinder Think of a cylinder with changing cross section
42
1999 BG Mobasseri42 8/29/2015 How to do it? Usage: –Cylinder(radius) where radius is the growing cross sectional radius described by a vector
43
1999 BG Mobasseri43 8/29/2015 Homework #3 Plot z=sin(sqrt(x^2+y^2)). Plot it using –mesh –surf, surfl, surfc –Experiment with shading: flat, faceted, interpolated –Experiment with lighting directions. For good effect type colormap(copper) after bringing up the plot.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.