Graphics and Visualisation: 3D Plot: Line Plots in 3D
Graphics and Visualisation: 3D Plot: Line Plots in 3D
Lecture 14:
Graphics and Visualisation: 3D Plot
Control 3D plots
If desired, axis ranges of 3D plots can be set with the axis
command:
>> axis([xmin, xmax, ymin, ymax, zmin, zmax]);
An important part of understanding a 3D plot is determining the
orientation that you are viewing the data from.
Use the following commands to help control a 3D plot:
>> box on;
Surface plotting in 3D
The plot3 function is suitable for displaying two
variables that are a function of one independent
variable:
x = f1(t)
y = f2(t)
>> contour(X, Y, Z)
>> Yvals = -2 : 1 : 2;
>> [X, Y] = meshgrid(Xvals, Yvals)
-1
-1
0
0
1
1
2
2
-2
-2
-1
-1
0
0
1
1
2
2
-2
-1
-2
-1
0
1
2
-2
-1
0
1
2
2D arrays == flat ?
In discrete terms, Matlab represents parametric
surfaces in terms of 2D arrays of X, Y, and Z values
that correspond to each (i, j) grid point on the
surface.
Hence the arguments to the mesh, surf, and contour
functions are 2D arrays of points.
In the plots shown so far, the X and Y 2D arrays are
"flat", but there is no need for them to be like that...
A triangular prism
A very wide variety of shapes can be
represented, e.g. a triangular prism can
be represented by:
X =
1.0
-0.5
-0.5
1.0
1.0
-0.5
-0.5
1.0
Y =
0.0
0.0
0.866
0.866
-0.866
-0.866
0.0
0.0
Z =
0.0
1.0
0.0
1.0
0.0
1.0
0.0
1.0
With this shading option, the colour of each facet is varied linearly across
the facet so that the shading at the edges of adjacent facets match (called
Gouraud shading). No mesh is drawn.
Example
>> [X Y Z] = cylinder([3 1 3 4 2 2 ],500);
>> surfl(X, Y, Z)
>> shading interp
The surfl function behaves just like surf but renders a surface
according to the current lighting model (the default lighting
model is fine for almost every purpose you might have).
The shading across the surface is no longer a function of its
"height".
Instead the shading is a function of the relative angle
between the incident light and the surface normal at each
point.
Lambertian shading
http://www.upvector.com/index.php?section=tutorials&subsection=tutorials/shading_1