0% found this document useful (0 votes)
3 views

3d Plot

Uploaded by

thanusavelan04
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

3d Plot

Uploaded by

thanusavelan04
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Chapter 10

Three-Dimensional Plots

MATLAB An Introduction With Applications, 6th Edition Slide deck by


Dr. Amos Gilat Dr. Greg Reese
The Ohio State University Miami University
1
10.0

Three-dimensional (3-D) plots useful


for presenting related 3-D points.
Common cases are
• Scalar or vector function of two
independent variables
• Scalar or vector data measurements
in 3-D space
• Movement over time 3-D space

2
10.0

MATLAB has many commands for


making 3-D plots. Will study
• Line plots
• Wire plots
• Surface plots
• Mesh plots
For more information, see Plotting and
Data Visualization in Help Window

3
10.1 LINE PLOTS

A three-dimensional line plot is a plot


obtained by connecting points in 3-D
space. MATLAB command is

• x,y, and z must be same size


• Remaining arguments are same as
in 2-D plots (Section 5.1)
4
10.1 LINE PLOTS

If the spatial coordinates of a set of


points are each functions of the same
independent variable, the coordinates
form a set of parametric equations.
• Often independent variable is time (t)
and the set shows how a particle
moves through space over time

5
10.1 LINE PLOTS

EXAMPLE
Suppose the spatial coordinates vary
with time as

Make a line plot for 0 ≤ t ≤ 6π

6
10.1 LINE PLOTS

7
10.2 MESH AND SURFACE PLOTS

Mesh and surface plots are 3-D plots


used to graph functions of the form
z = f(x,y)
• x and y are independent variables, z is a
dependent variable
• A mesh plot connects values of z with
lines to form the outline of a surface
• A surface plot connects lines in a mesh
plot with planes to show a solid
representation of the surface
8
10.2 MESH AND SURFACE PLOTS

Three steps to making mesh or surface plot


1. Create grid in the x-y plane that
contains points you're interested in
2. Calculate the value of z at every point of
the grid
3. Make the plot

9
10.2 MESH AND SURFACE PLOTS

Creating a grid in the x y plane (Cartesian coordinates):

The grid is the set of points on which


you want to evaluate z. For example

10
10.2 MESH AND SURFACE PLOTS

Can define the grid by using two matrices,


X and Y
• X has x-coordinates of all grid points
• Y has y-coordinates of all grid points
For grid shown

11
10.2 MESH AND SURFACE PLOTS

Note that
• X is made of identical rows because each row
of grid has the same x-coordinates
• Y is made of identical columns because each
column of grid has same y-coordinates
To make matrices, use MATLAB command

12
10.2 MESH AND SURFACE PLOTS

13
10.2 MESH AND SURFACE PLOTS

Calculating the value of z at each point of the grid:


Calculate value of z at each point by
using elementwise calculations.
• X and Y must be same dimensions
• Resulting z will also be same dimension
For example grid and
>> Z = X.*Y.^2 ./ (X.^2 + Y.^2)

14
10.2 MESH AND SURFACE PLOTS

Making mesh and surface plots:


• To make mesh plot use mesh(X,Y,Z)
• To make surface plot use surf(X,Y,Z)

EXAMPLE
Make mesh and surface plots of over
domain -1≤ x ≤ 3 and 1 ≤ y ≤ 4

15
10.2 MESH AND SURFACE PLOTS

16
10.2 MESH AND SURFACE PLOTS

Additional comments on the mesh command:


• MATLAB colors surface plots with colors that
vary with value of z
Can make color constant by using the Plot Editor
in the Figure Window or by using colormap
command. (See Help on colormap for details)
• By default, mesh draws a grid. Issue
command grid off to prevent grid from
appearing
• Can draw box around plot with box on

17
10.2 MESH AND SURFACE PLOTS

Can also use mesh(Z) and surf(Z)


• Command uses row indexes on the x-axis
and column indexes on the y-axis
Table 10-1 in book shows lots of
variations available with mesh and
surf commands

18
10.3 PLOTS WITH SPECIAL GRAPHICS

Table 10-2 in book shows some


commands for specialized 3-D plots.
Can get more information from Help
Window or by using help command

19
10.3 PLOTS WITH SPECIAL GRAPHICS

Polar coordinates grid in the x y plane:


To make 3-D plot of function z = f(r,θ)
1. Make grid of values of θ and r with
meshgrid
2. Compute value of z at each grid point
3. Convert grid with polar coordinates to
grid with Cartesian coordinates using
MATLAB's pol2cart command
4. Make 3-D plot using values of z and the
Cartesian coordinates
20
10.3 PLOTS WITH SPECIAL GRAPHICS

21
10.4 THE view COMMAND

The view command controls direction


from which you view plot. Command is
view(az,el) or view([az el])
• az – azimuth: angle (in degrees) in x-y plane
measured from negative y axis and positive
in counterclockwise direction
• el – elevation: angle of
elevation (in degrees)
from x-y plane. Positive
in direction of positive
z axis 22
10.4 THE view COMMAND

Default view angles are az = -37.5o and el = 30o

az = -37.5o and el = 30o az = 20o and el = 35o

23
10.4 THE view COMMAND

Can project 3-D curve onto 2-D plane by


specific settings of azimuth and elevation

See Fig. 10-5 through Fig. 10-7 for


examples of projections

24
10.4 THE view COMMAND

view can also set a default view


• view(2) sets default to top view (projection
onto x-y plane with az = 0o, and el = 90o
• view(3) sets default to standard 3-D view
(az = –37.5o, and el = 30o)

25
10.4 THE view COMMAND

Can also set viewing direction by selecting


a point in space from which to view plot
• Command has form view([x y z])
x, y, and z are the coordinates of the point
Viewing direction is direction from specified point
to origin of coordinate system
Viewing direction independent of distance to
origin, e.g., view is same with point [6 6 6] as with
point [10 10 10]
Set top view with [0 0 1]
Set side view of x-z plane from negative y
with [0 –1 0] 26

You might also like