Fall 2006AE6382 Design Computing1 Three Dimensional Plotting Learning Objectives –Understand the anatomy of a 3D plot –Basics of constructing plots in.

Slides:



Advertisements
Similar presentations
PowerPoint Heaven – The Power to Animate
Advertisements

Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Introduction to Excel Formulas, Functions and References.
Introduction to M ATLAB 2 Graphics Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Exponential Functions Logarithmic Functions
1 CA202 Spreadsheet Application Combining Data from Multiple Sources Lecture # 6.
Chapter 11 Above: Principal contraction rates calculated from GPS velocities. Visualized using MATLAB.
Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Introduction to Matlab:
Section 2.3 Gauss-Jordan Method for General Systems of Equations
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Automating Tasks With Macros
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
16 MULTIPLE INTEGRALS.
1 Introduction to MatLab MatLab stands for Matrix Laboratory. As the name suggests most of the programming operations have as input or output a matrix.
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
Academic Computing Services 2010 Microsoft ® Office Visio ® 2007 Training Get to know Visio.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Matlab Training Sessions 6,7: Plotting. Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan ) 2.Fundamentals (Operators) 3.Fundamentals.
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
Plotting – 3-Dimensional. 3D Plots versus 2D Plots 3-dimensional plots, in contrast to 2-dimensional ones, has a third axis (often called the z-axis).
Sample size vs. Error A tutorial By Bill Thomas, Colby-Sawyer College.
Textbook: Chapter 11 Part : 3D-Plotting CSE 1010.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Microsoft ® Office Excel 2007 Working with Charts.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 4 : Polynomial Edward Cheung Room W311g 2008.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
CTS130 Spreadsheet Lesson 9 - Building Charts. What is a Chart? A chart is a visual display of information in a worksheet. Charts can help you make comparisons,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
1. Chapter 15 Creating Charts 3 Charting Data in Word A chart or graph presents data visually. A chart depicts numeric data in a graphical format. If.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
2D Routines in 3D. Outline Announcements –HW II--due Friday. 5PM HW1 & Cookie Grids & Meshes Representing f(x,y) Lines & Surfaces in 3D Survey.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
June 14, ‘99 COLORS IN MATLAB.
Multiplication of Common Fractions © Math As A Second Language All Rights Reserved next #6 Taking the Fear out of Math 1 3 ×1 3 Applying.
EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers.
Computer Graphics Matrices
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
EEE 242 Computer Tools for Electrical Engineering
Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data.
CS112 Scientific Computation Department of Computer Science Wellesley College Kodak moments 3-D Visualization and Color.
CS112 Scientific Computation Department of Computer Science Wellesley College Kodak moments 3-D Visualization and Color.
Advanced Plotting Techniques Chapter 11 Above: Principal contraction rates calculated from GPS velocities. Visualized using MATLAB.
Reading and Writing Image Files
ENEE222 Elements of Discrete Signal Analysis Lab 11 1.
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Graphing Equations and Inequalities
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Yang-Ming University, Taipei, Taiwan
Plotting Signals in MATLAB
Presentation transcript:

Fall 2006AE6382 Design Computing1 Three Dimensional Plotting Learning Objectives –Understand the anatomy of a 3D plot –Basics of constructing plots in 3D –How to choose different plot types for best effects Topics –Plotting in 3D: major differences –The meshgrid() function to create plaids –3D mesh plots –3D surface plots –shading and light sources –Contour plots –Use of color to add a 4th dimension

Fall 2006AE6382 Design Computing2 Background Plotting in 3D and 3D data visualization is where Matlab’s power really becomes apparent! Matlab defines a number of different kinds of 3D plots but you will probably find 3 or 4 to be the most useful: –x,y,z 3D line plot: plot3( ) –mesh plot: mesh( ) –surface plot: surf( ) –contour plot: contour( ) –combo surface/mesh with contour: surfc( ) The surface plotting can also be applied to create realistic 3D objects by defining and plotting their exterior surfaces! We can only touch lightly on this vast area of Matlab…

Fall 2006AE6382 Design Computing3 Anatomy of a 3D Plot There are MANY options for plotting in 3D but we will consider only the basics: –Plotting a curve in 3D: plot3(x,y,z) –Plotting a surface, z=f(x,y), in 3D: mesh( ) & surf( ) –There are also several other plotting topics that we will NOT cover or discuss in class (but you might find interesting to explore on your own): ribbon plots quiver plots (showing vectors) volume plots advanced colormap use

Fall 2006AE6382 Design Computing4 2D Plots vs 3D Line Plots Actually, every 2D plot is simply a 3D plot without the 3rd dimension being specified. >> clf >> x=0:0.1:2.*pi; >> plot(x,sin(x)) Rotate 3D button: experiment with how it works…

Fall 2006AE6382 Design Computing5 3D Line Plot This is the simplest (and least useful) 3D plot and is really just a generalization of the 2D function: >> x=0:0.1:3.*pi; >> z1=sin(x); >> z2=sin(2.*x); >> z3=sin(3.*x); >> y1=zeros(size(x)); >> y3=ones(size(x)); >> y2=y3./2; >> plot3(x,y1,z1,'r',x,y2,z2,'b',x,y3,z3,'g') >> grid on >> xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis')

Fall 2006AE6382 Design Computing6 3D Line Plot (2) These examples may be a little more useful… >> clf >> turns=40.*pi; >> theta=linspace(0,turns,4000); >> x=cos(theta).*(turns-theta)./turns; >> y=sin(theta).*(turns-theta)./turns; >> z=theta./turns; >> plot3(x,y,z) >> grid on >> text(0.5,0.5,0.75,'Here is a piece of text!'); >> theta=0:0.1:10.*pi; >> plot3(sin(theta),cos(theta),theta) >> grid on theta=0:0.1:10.*pi; >> plot3(sin(theta),cos(theta),theta) >> grid on

Fall 2006AE6382 Design Computing7 3D Surface Plots It is often desirable to plot functions of the form: z=f(x,y) –for each (x,y), we can compute a value for z –this defines a surface in 3D space If we can define (x,y) at regular intervals, Matlab provides powerful ways to plot the resulting function as a mesh or surface in 3D. The (x,y) values stored in arrays will define a grid of mesh points through which the surface will be created. There are tools in Matlab to handle the situation in which (x,y) are not defined in a grid, but we won't consider them in this course. We will look into how colors can be employed to add the equivalent of a 4th dimension…

Fall 2006AE6382 Design Computing8 Defining the (x,y) Values We need a way to create the range of (x,y) values needed to compute f(x,y) x = y = z=f(x,y) This won't work because we need all values of y for each value of x and vice versa to evaluate function over entire region shown xx = yy = z=f(xx,yy) This works: corresponding elements of xx & yy contain the x and y coordinates to be used for f(x,y) at that point NOTE: xx varies along ROWS while yy varies along COLUMNS NOTE: xx varies along ROWS while yy varies along COLUMNS

Fall 2006AE6382 Design Computing9 The meshgrid() Function Matlab provides a function to compute these arrays: >> x=-3.5:3.5; >> y=-2.5:2.5; >> [xx,yy]=meshgrid(x,y) xx = yy = NOTE #1: xx varies along ROWS while yy varies along COLUMNS NOTE #2: For any (i, j), the value in xx is the x coordinate, while the value in yy is the y coordinate: xx(3,1) = -3.5 yy(3,1) = -0.5 So (x,y) = (-3.5, -0.5) NOTE #4: We can use array math to efficiently compute the z values when z=f(x,y) NOTE #3: Matlab calls these arrays "plaids"

Fall 2006AE6382 Design Computing10 >> x=-3:3; >> y=-3:3; >> [xx,yy]=meshgrid(x,y) xx = yy = >> zz=xx.^2 + yy.^2; >> mesh(xx,yy,zz) Simple Example Using meshgrid() In this case we will plot z = (x 2 + y 2 ) over the range -3  x  3 and -3  y  3 NOTE: Matlab's array instructions make this a deceptively simple calculation for all values at once…

Fall 2006AE6382 Design Computing11 Calculation of f(x,y) Calculation of f(x,y) can be tricky depending on exactly how it is defined over the "plaid" (see MM pg. 384) >> nc=length(x); % number of columns in z >> nr=length(y); % number of rows in z >> z=zeros(nr,nc); % initialize z (for speed) >> for k=1:nc z(:,k) = x(k).^2 + y(:).^2; end >> mesh(xx,yy,z) NOTE: It can be very tricky to keep track of the row and column indices in this kind of calculation… (it appears that the text in the book is incorrect) Column-wise Calculation of z = f(x,y)

Fall 2006AE6382 Design Computing12 Calculation of f(x,y) - cont'd Worst case is that you may have to compute each element of z explicitly as follows: >> nc=length(x); % number of columns in z >> nr=length(y); % number of rows in z >> z=zeros(nr,nc); % initialize z (for speed) >> for kc=1:nc for kr=1:nr z(kr,kc) = x(kc).^2 + y(kr).^2; end >> mesh( >> mesh(xx,yy,z) NOTE: It can be very tricky to keep track of the row and column indices in this kind of calculation… Element-by-element Calculation of z = f(x,y)

Fall 2006AE6382 Design Computing13 Key Concepts for z=f(x,y) Plots 3D plotting introduces several key concepts: –Meshes versus Surfaces –Hidden line removal –Pedestals and contours –Color maps and pseudo-coloring –Viewpoints and camera control (advanced!) –Shading and lighting (advanced) The following figures demonstrate these concepts, but you are encouraged to check this out in your textbook (using Matlab’s graphic brings out the real fun in using this powerful software!).

Fall 2006AE6382 Design Computing14 [X,Y,Z] = sphere(12); subplot(1,2,1); mesh(X,Y,Z), title('Figure 26.5a: Opaque'); hidden on; axis square off; subplot(1,2,2); mesh(X,Y,Z),title('Figure 26.5b: Transparent'); hidden off; axis square off; Exploring Hidden Line Removal This uses an interesting built-in function sphere( ) Hidden lines: –ON: shows white inside mesh –OFF: shows transparent mesh

Fall 2006AE6382 Design Computing15 Let's Explore the mesh( ) Function We'll use peaks( ) to create a z=f(x,y) function that is interesting and shows off the 3D plotting Note: you should check help peaks and help mesh and also the textbook for further details on these functions >> [x,y,z]=peaks(30); >> mesh(x,y,z) >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis') Suggestion: Try using hidden off and hidden on to see what happens.

Fall 2006AE6382 Design Computing16 Exploring meshc Plots meshc( ) adds a contour plot directly below the mesh –helps visualize the contours –can locate the peaks and dips >> [x,y,z]=peaks(30); >> meshc(x,y,z) >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis') Hint:: If you just finished the previous example, you need only type in the new meshc( ) command.

Fall 2006AE6382 Design Computing17 Exploring meshz Plots This special variation allows you to emphasize the zero plane in the mesh plot >> [x,y,z]=peaks(30); >> meshz(x,y,z) >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis')

Fall 2006AE6382 Design Computing18 Exploring waterfall Plots This is another variation on the mesh plot and can also be useful in some special cases >> [x,y,z]=peaks(30); >> waterfall(x,y,z) >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis')

Fall 2006AE6382 Design Computing19 Let's Explore the surf( ) Function So far we have only been able to plot meshes to represent the surface –can hide hidden lines to clarify the surface shape –still appears as a wireframe-like shape Matlab provides a function that will fill in the mesh with facets (surfaces with 3 or 4 corners but not necessarily plane surfaces) –we'll see that these can produce very realistic appearing surfaces in 3D –can control appearance of mesh –can change color mapping to reveal other information –can add lighting

Fall 2006AE6382 Design Computing20 Exploring surf Plots (shading faceted) The basic function uses the default shading faceted and this shows the mesh: >> [x,y,z]=peaks(30); >> surf(x,y,z) >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis')

Fall 2006AE6382 Design Computing21 Exploring surf Plots (shading flat) shading flat will eliminate the mesh and leave the facets colored with a constant color value >> [x,y,z]=peaks(30); >> surf(x,y,z) >> shading flat >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis')

Fall 2006AE6382 Design Computing22 Exploring surfc Plots (shading interp) surfc acts much like meshc with a contour plot drawn below the surface shading interp interpolates color over each facet >> [x,y,z]=peaks(30); >> surfc(x,y,z) >> shading interp >> axis tight >> xlabel('x-axis') >> ylabel('y-axis') >> zlabel('z-axis') NOTE: shading interp can take time to execute and the figure may cause plotting problems

Fall 2006AE6382 Design Computing23 Changing the Viewing Direction You can change the orientation of the object –Viewing direction: view(az,el) or you can use the rotate3d button on the view toolbar on the figure window menu –Camera direction: this is best controlled from the camera toolbar on the figure window menu z y x azimuth elev viewpoint » view(-45,60)

Fall 2006AE6382 Design Computing24 Adding a Colorbar You can use the colorbar command to add a color bar that defines the color used in the plot. Use help colorbar to find out what the other options are… NOTE: You should check out the instructions on how to use the Property Editor and the tools in the Figure window to interactively add text and labels to various parts of this 3D graph. NOTE: You should check out the instructions on how to use the Property Editor and the tools in the Figure window to interactively add text and labels to various parts of this 3D graph.

Fall 2006AE6382 Design Computing25 Using Color as a 4 th Dimension Matlab associates a “colormap” with each figure window –this is a 3 column array in which columns #1-3 control the Red, Blue & Green colors (defined using a 0-1 range) –each row defines a specific color –colors are limited by the color display capabilities of the computer –these, along with a few fixed colors, are the colors Matlab will use in the figure window (each figure window has its own separate colormap) –Matlab predefines a number of useful colormaps JET, HSV, GRAY, HOT, COOL, BONE, COPPER, PINK, FLAG, PRISM see help graph3d for more information and other colormaps use colormap hsv or colormap(‘hsv’) to change colormap default restores the colormap to default values –use the colorbar command to display the color bar by itself or alongside a plot (see help )

Fall 2006AE6382 Design Computing26 Using Color as a 4 th Dimension (2) Matlab uses “pseudo-color” to change the color in a mesh or surf plot –colors can be based on the z values (default) –you can specify the color variable in mesh() and surf() Use caxis([cmin cmax]) to define the max and min values that are mapped to the colormap >> caxis([-5 5]); >> colorbar >> caxis([-5 5]); >> colorbar >> caxis([-50 50]); >> colorbar >> caxis([-50 50]); >> colorbar

Fall 2006AE6382 Design Computing27 Using Color as a 4 th Dimension (3) mesh() and surf() can accept a "color" argument that defines the color used over the plaid. >> caxis('auto') >> surf(x,y,z,y) >> axis tight >> ylabel('y-axis') Here we have used the y values as the color variable. This shows curvature of the surface as the color variable. >> C=del2(z); % compute Laplacian >> surf(x,y,z,C) >> axis tight >> colorbar

Fall 2006AE6382 Design Computing28 Contour Plots Matlab provides several functions to draw contours –contour(): draws simple contour map with N intervals –contourf(): draws a contour with filled contours –contour3(): draws a contour map in 3D » [x,y,z]=peaks(30); » contour(x,y,z,10) » colorbar » xlabel('x-axis') » ylabel('y-axis') » [x,y,z]=peaks(30); » contourf(x,y,z,10) » colorbar » xlabel('x-axis') » ylabel('y-axis') NOTE: See textbook for other options. NOTE: See textbook for other options.

Fall 2006AE6382 Design Computing29 Example Here is a simple example to illustrate 3D plotting –it is the “sinc” function (sin(r)/r) where r=radius –we need to add eps to avoid inf when dividing by zero » [xx,yy]=meshgrid(-4.*pi:pi./5:4.*pi); » R=sqrt(xx.^2 + yy.^2)+eps; % radius » zz=sin(R)./R; » surf(xx,yy,zz) » axis tight Question: How could you handle a situation when the data are not defined on a regular grid (when the points are unevenly spaced)? Question: How could you handle a situation when the data are not defined on a regular grid (when the points are unevenly spaced)?

Fall 2006AE6382 Design Computing30 Incentives… Here is a sphere with 2 lights added and the shading adjusted to show the lights (gouraud shading). See if you can create similar figures! Now you really don't have any reason why you can't produce outstanding graphics for all your reports and projects!

Fall 2006AE6382 Design Computing31 Problem Solving Create a plot of the sinc(R) function shown in a previous slide, but in this case make the plot region a circular area in the xy plane that has a radius of 3  (Hint: you will need to create an xy plaid but computed from a grid defined using polar coordinates.) Add a circular disk of radius = 3  to the above sinc(R) plot. (Hint: you can use hold on to add additional surfaces using the surf command just like you did for plot() ). Now add a vertical plane (y=0) and a second vertical plane (x=0) to the plot. This effectively partitions the surface into 8 regions.

Fall 2006AE6382 Design Computing32 Summary Review questions –Describe 3D plotting in MATLAB, –What is a “scalar function in two variables?” –What is a plaid? What do they look like? –Describe differences between surface and mesh plot, and all their variants. –What do the shading, hidden commands do? Action Items –Review the lecture –Work through the examples –See if you can figure out how to use color