CHAPTER 3

image

Three-Dimensional Graphics, Warped Curves and Surfaces, Contour Graphics

3.1 Three-Dimensional Graphics (3-D), Warped Curves

The basic commands that MATLAB uses to draw graphs that generate a line in three dimensions or warped curves are the following:

  • plot3(X, Y, Z) draws the set of points (X, Y, Z), where X, Y and Z are vectors. X, Y and Z can also be arrays of the same size, in which case a graph is made for each triplet of rows and on the same axis. For complex values of X, Y and Z, the imaginary parts are ignored.
  • plot3(X,Y,Z,S) draws the plot (X, Y, Z) with the settings defined in S. Usually S consists of two-symbols between single quotes, the first of which sets the color of the line of the graph, and the second sets the character to be used in the plotting. The possible values of colors and characters have been already described to explain the command plot.
  • plot3(X1,Y1,Z1,S1,X2,Y2,Z2,S2,X3,Y3,Z3,S3,...) combines, on the same axes, graphs defined for the quads (Xi, Yi, Zi, Si). It is a way of representing various functions on the same graph.

Here is an example:

>> x = 0:pi/50:10*pi;
>> y = sin(x);
>> z = cos(x);
>> plot3(x, y, z)

This generates the graph in Figure 3-1.

3.2 Polygons in Three Dimensions

MATLAB also allows for drawing polygons in three dimensions. To do this, use the following commands:

  • fill3(X,Y,Z,C) draws the compact polygon whose vertices are the triples of the components (Xi, Yi, Zi) of the column vectors X, Y and Z. C can be a row vector of numbers, with the same number of columns as X and Y; or C can be a column vector of numbers, with the same number of rows as X and Y; or C can be a character that uses the colorspec characters shown like ‘k’ for black. When C is a numeric vector, it is used as a scaled index into the current colormap. If X, Y and Z are of the same dimension, several polygons corresponding to each triple vector column (X.j, Y.j, Z.j) may be represented as matrices simultaneously. In this case, C can be a row vector. Cj elements determine the unique color of each polygon corresponding to the triple of vector column (X.j, Y.j, Z.j). C may also be an array of the same dimension as X, Y and Z, in which case the elements determine the colors of each point (Xijk, Yijk, Zijk) of the set of polygons.
  • fill3(X1,Y1,Z1,C1,X2,Y2, Z2, C2,...) draws the compact polygon whose vertices are given by the points (Xi, Yi, Zi) and Ci.

Here is an example:

>> x = cos(0:0.01:8*pi);
>> y = sin(0:0.01:8*pi);
>> z = 0:0.01:8*pi;
>> fill3(x,y,z,'r')

This generates the graph of Figure 3-2.

3.3 Graphics in Parametric 3-D Coordinates

Let’s see here how MATLAB draws curves in parametric coordinates in space, also known as warped curves in parametric coordinates. The fundamental problem is to get graphs of tridimensional functions in which the variable x, y and z depend, in turn, on a parameter t.

The command that can be used is plot3 and all its variants, by suitably defining intervals of variation of the parameter, not by the independent variable as it was until now.

This type of graphic is very useful in certain matters, such as, for example, differential geometry.

Here is an example:

>> t = -4*pi:0.01:4*pi;
>> x = cos(t) .^ 2;
>> y = sin(t) .* cos (t);
>> z = sin(t);
>> plot3(x, y, z)

This generates the graph in Figure 3-3.

3.4 Surfaces, Meshes and Contours

So far we have seen the 3D graphics based on a line that moves in three dimensions to form a warped curve. Now let’s see how 3D graphics corresponding to surfaces and their different variants are made available.

3.5 Surfaces in Explicit Coordinates

Surface graphics allow for dense representations of tridimensional figures, and in particular of functions of two variables. The first step in representing a function of two variables z = f(x,y) using a surface chart, is to use the command meshgrid, which basically defines the array of points (X, Y) on which the function of two variables is evaluated for its graphical representation. Its syntax is as follows:

[X, Y] = meshgrid(x,y)

Parameters x and y are vectors that are replicated into to matrices X and Y. Each matrix will have the same number of rows as the length of x, and the same number of columns as the length of y. The increments of values in each of the vectors determine the “spacing” of the resulting grid. For example, x of [-10:0.1:10] and y of [-2:0.1:2] will result in X of 40 columns and 100 rows. Each columns will have the same sequence of values between -10 and +10. While Y will also have 40 columns and 100 rows, each of the rows will have the same sequence of values between -2 and +2.

The second step is to use the available commands to effect the result, which are as follows:

  • surf(X,Y,Z,C) represents the graph of the function’s surface z = f(x,y), using the colors specified in C. The C argument can be ignored.
  • surfc(X,Y,Z,C) represents the graph of the function’s surface z = f(x,y) with the chart’s corresponding isolines (contour lines projected onto the X Y-plane).
  • surfl(X, Y, Z) represents the graph of the function’s surface z = f(x,y), making the drawing with shading (highlights from a light source).

EXERCISE 3-1

Represent the surface of the slope-intercept form:

Eqn3-1.jpg -14/2 < x, y < 14/2

Also represent the surface with its contour.

>> [X, Y] = meshgrid(-7.5:.5:7.5);
>> Z = sin(sqrt(X.^2+Y.^2))./sqrt(X.^2+Y.^2);
>> surf(X, Y, Z)

This gives the graph of Figure 3-4.

The surface with the outline (contour) graph is shown in Figure 3-5. The following syntax is used:

>> [X, Y] = meshgrid(-7.5:.5:7.5);
>> Z = sin(sqrt(X.^2+Y.^2))./sqrt(X.^2+Y.^2);
>> surfc(X, Y, Z)

Figure 3-6 shows the chart shaded, using the syntax:

>> [X, Y] = meshgrid(-7.5:.5:7.5);
>> Z = sin(sqrt(X.^2+Y.^2))./sqrt(X.^2+Y.^2);
>> surfl(X, Y, Z)

3.6 Mesh Graphics

A three-dimensional mesh graph is defined by a function z = f(x,y), so that the points on the surface are represented on a grid, result of the z values are given by f(x,y) on corresponding points of the (x, y) plane. The appearance of a mesh chart is like a fishing net, with points on the surface on the nodes of the network. Actually, it is a graph of surface whose graph has the form of a network.

To represent a mesh graph, use the command mesh and its variants, whose syntax are as follows:

  • mesh(X,Y,Z,C) represents the graph of the mesh function z = f(x,y), drawing the grid lines that compose the mesh with the colors specified in C. The C argument is optional.
  • meshz(X,Y,Z,C) represents the graph of the mesh function z = f(x,y) with a curtain around the perimeter of the grid that drops to the bottom of the z-axis giving the impression of a draped tablecloth.
  • meshc(X,Y,Z,C) represents the graph of the mesh function z = f(x,y) along with a corresponding contour chart like surfc above (with contour lines projected onto the XY-plane).

EXERCISE 3-2

Represent the mesh graph for the surface of equation:

z = xe (-x ^ 2 - y ^ 2)        - 2 < x, y < 2

Also add their contours (a contour chart) and include a curtain.

The syntax presented here gives as a result the graph in Figure 3-7:

>> [X, Y] = meshgrid(-2:.1:2,-2:.1:2);
>> Z = X .* exp(-X.^2 - Y.^2);
>> mesh(X, Y, Z)

Figure 3-8 presents the mesh along with the contour graph (or contour chart) for the syntax as follows:

>> [X, Y] = meshgrid(-2:.1:2,-2:.1:2);
>> Z = X .* exp(-X.^2 - Y.^2);
>> meshc(X, Y, Z)

Finally, Figure 3-9 represent the mesh graphic and curtain option. The syntax is as follows:

>> [X, Y] = meshgrid(-2:.1:2,-2:.1:2);
>> Z = X .* exp(-X.^2 - Y.^2);
>> meshz(X, Y, Z)

3.7 Contour Graphics

Another option for visualizing a function of two variables is to use level curves calls (a system of dimensional planes. These curves are characterized as such because they are the points (x, y) on which the value of f(x,y) is constant. Thus, for example, in the weather charts, level curves representing the same temperature points are called isotherms, and contour lines of equal pressure, isobars. Contour lines, representing heights (values of f(x,y) that are equivalent, can describe surfaces in space. Thus, drawing different contours corresponding to constant heights, can be described as a map of lines on the surface level, MATLAB calls a contour graph. The contour plots can be represented in two and three dimensions.

A map showing the regions of the Earth’s surface, whose contour lines represent the height above the sea level, is called a topographic map. These maps, therefore show the variance of z = f(x,y) with respect to x and y. When the space between contour lines is large, it means that the variation of the variable z is slow, while a small space indicates a rapid change of z.

Commands used in MATLAB for the representation of isographs (contour lines) are as follows:

  • contour(Z) draws the outline graph (contour lines) for the Z matrix graph. The number of contour lines to be used are chosen automatically.
  • contour(Z,n) draws the graph outline (contour lines) for the Z matrix using n contour lines.
  • contour(x, y, Z, n) draws the graph outline (contour lines) for the Z matrix in the X and Y axes using scaling defined by the vectors x and y (with n contour lines).
  • contour3(Z), contour3(Z,n) and contour3(x, y, Z, n) draws the contour in 3-dimensional plots.
  • pcolor(X, Y, Z) draws a graph outline (contour lines) to the matrix (X, Y, Z) using a representation based on densities of colors. It is often called a density chart.

EXERCISE 3-3

Given the surface of equation:

z = Sine(x) Sine(y)         - 2 < x, y < 2

Represent it with its contour. Then represent its two-dimensional outline with 20 graph lines and its three-dimensional outline with 50 chart lines. Also draw the corresponding density chart.

Figure 3-10 shows the graph of the surface with its contour. The syntax is as follows:

>> [X, Y] = meshgrid(-2:0.1:2);
>> Z = sin(X) .* sin(Y);
>> surfc(X, Y, Z)

Figure 3-11 shows the two-dimensional contour graph using 20 lines. The syntax is as follows:

>> [X, Y] = meshgrid(-2:0.1:2);
>> Z = sin(X) .* sin(Y);
>> contour(Z, 20)

Figure 3-12 shows the three-dimensional contour graph using 50 lines. The syntax is as follows:

>> [X, Y] = meshgrid(-2:0.1:2);
>> Z = sin(X) .* sin(Y);
>> contour3(Z, 50)

Finally, Figure 3-13 represents the density graph (with the contour shaded according to different intensities of color). The syntax is as follows:

>> [X, Y] = meshgrid(-2:0.1:2);
>> Z = sin (X) .* sin(Y);
>> pcolor(X, Y, Z)

3.8 Manipulating Three-Dimensional Graphics

There are commands in MATLAB which allow you to change the appearance of the same graph, either by your shader, the scale of its themes, colors, hidden lines, the point of view from which one can observe it, etc. Below, some of these commands are:

  • axis([xmin ymin, ymax, zmin zmax max x]) places intervals of variation of the axes at the indicated values. It lso accepts the options ‘ij’, ‘square’, ‘equal’, etc, identical to those already seen for two dimensions.
  • view([x, y, z]) places the point of view of the figure at the point’s Cartesian coordinates (x, y, z).
  • view([az, el]) puts the angle of view of the figure in the point of azimuth (horizontal rotation) ‘az’ and elevation (vertical lift).
  • hidden controls the presence of hidden lines in the graph. These lines come with hidden on and go with hidden off.
  • shading controls the type of shadow of a surface created with commands surf, mesh, pcolor, fill and fill3. The option shading flat situates a smooth shading option. The option shading interp implements dense shading and the option shading faceted (the default) opts for normal shading.
  • colormap(M) locates the matrix M as the current color map. M must have three columns and only contain values between 0 and 1. It can also be a matrix whose rows are vectors RGB type [r g b]. All arrays must have 3 columns and p rows.
  • Brighten(p) adjusts the lighting of the figure. The variation of p is the interval (-1,1), and as the values of p approach - 1, the figure darkens, while as p values approach 1, the figure illuminates.
  • image(A) produces a two-dimensional image with colors based upon the values of the elements of the array A, and is used to display photographs and drawings adapted to the specified colormap. Each element (m, n) of the matrix A affects a rectangular section of the image.
  • caxis([cmin cmax]) places the minimum and maximum values of the color scale (defined by the colormap and intrinsically related to the divisions that are made in the axes via grids) for a chart. Therefore, it enables you to use only a subset of colors defined by the colormap.

EXERCISE 3-4

Given the surface equation:

z = x2 - y2         - 2 < x, y < 2

represent it with strong lighting, dense shadows and gray colors. Using the same axis, show four different points of view and with the shading by default.

>> [X, Y] = meshgrid(-2:0.05:2);
>> surf(X,Y,Z),shading interp,brighten(0.75),colormap(gray(5))

This generates the graph in Figure 3-14.

We will now present in Figure 3-15 the surface focused from four different points of view. The syntax is as follows:

>> [X, Y] = meshgrid(-2:0.05:2);
>> Z = X .^ 2 – Y .^ 2;
>> subplot(2,2,1)
>> surf(X,Y,Z)
>> subplot(2,2,2)
>> surf(X,Y,Z),view(-90,0)
>> subplot(2,2,3)
>> surf(X,Y,Z),view(60,30)
>> subplot(2,2,4)
>> surf (X, Y, Z), view (- 10, 30)

3.9 Parametric Surfaces

MATLAB allows you to represent surfaces whose components depend on specified variations in parameters. To do this, you can use the commands surf and mesh, by properly defining the variables x, and z.

Cylindrical and spherical coordinate surfaces are representable in MATLAB, parameterizing them in advance.

In terms of surfaces of revolution, they always require ranges, which allow their graphical representation with MATLAB.

EXERCISE 3-5

Draw the surface of parametric coordinates:

x = 4cos(r) sec(t)   y = 2sine(r) sec(t)   z = tan(t)    -2π< r <2π,  -π< r <π

>> r = [-2*pi:0.1:2*pi]';
>> t = [-pi:0.1:pi];
>> X = 4 * cos(r) * sec(t);
>> Y = 2 * sin(r) * sec(t);
>> Z = ones(size(r)) * tan(t);
>> surf(X,Y,Z)
>> shading interp

Note that “ones” as used above is a function that produces a vector or matrix that is populated by ones.  Similarly, “zeros” is populated by zeroes.

The graph is shown in Figure 3-16.

EXERCISE 3-6

Create the graph of the surface of revolution that is turning the function Sine (x) around the Z axis. also create the graph of the surface of revolution rotating the function e ^ x around the Y axis.

To obtain the equation of the surface, on the assumption that the rotation is around the Z axis, consider the graph of the generating curve y = r(z) in the plane YZ. Turning this graph around the Z axis forms a surface of revolution. The sections with flat z = z0 are circles whose RADIUS is r (z0) and equation x2 + y2 = [r(z0)]2. That means that the equation x2 + y2 = [r (z)] 2 describes the points on the surface of revolution. For our problem, we have r (z) = Sine (z) and the curve x2+ y2= Sine [z]2, which are parametric for the purpose of input for MATLAB graphics:

>> r =(0:0.1:2*pi)';
>> t =(-pi:0.1:2*pi);
>> X= cos (r)*sin (t);
>> Y= sin(r)*sin (t);
>> Z= ones (1, size (r))'* t;
>> surf(X,Y,Z), shading interp

This generates the graph in Figure 3-17.

If we propose this MATLAB entry:

r =(0:0.1:2*pi)';
t =(-2:0.1:2);
X= cos (r)*exp (t);
Y= ones(1, size(r))'*t;
Z= sin(r)*exp (t);
surf(X,Y,Z), shading interp

You get the graph in Figure 3-18, which has been found in the same way as the previous one, but rotating the exponential function around the Y axis (the generating curve is now the function e ^ x).

EXERCISE 3-7

Represent the cylinder {t, Sine [t], u}, with {t, 0, 2Pi} and {u, 0, 4} by revolving {Cos [t](3+Cos[u]), Sine [t](3+Cos[u]), Sine [u]}, with {t, 0, 2 Pi} and {u, 0, 2Pi}.

>> t = [0:0.1:2*pi]';
>> r = [0:0.1:4];
>> X = sin(t) * ones(size(r));
>> Y = cos(t) * ones(size(r));
>> Z = ones(size(t)) * r;
>> surf(X,Y,Z)
>> shading interp

You get the graph in Figure 3-19.

To represent the torus of revolution, we use the following syntax:

>> r = [0:0.1:2*pi]’;
>> t = [0:0.1:2*pi];
>> X = [3 + cos(r)] * cos(t);
>> Y = [3 + cos(r)] * sin(t);
>> Z = sin(t)’ * ones(size(t));
>> surf(X,Y,Z)
>> shading interp

We get the graph in Figure 3-20.

3.10 Special Geometric Forms

MATLAB enables commands to generate cylinders and spheres. We have:

  • [X, Y, Z] = cylinder(r, n) draws the cylinder generated by the curve r, which has n points (n = 20 per default) on the horizontal section of the circumference that is aligned with the Z axis.
  • [X, Y, Z] = sphere (n) draws a sphere (by default n = 20).

As an example, let’s represent the cylinder generated by the curve 4Cos (t) when t varies between 0 and 2π. The syntax will be as follows:

>> t = 0:pi/10:2 * pi;
>> [X, Y, Z] = cylinder(4 * cos(t));
>> surf(X, Y, Z)

This generates the graph of Figure 3-21.

3.11 Other Graphics Handling Options

Graphic characteristics treated so far belong to the high level MATLAB GUI. However, there are low level (Handle Graphics) commands that allow creation and manipulation of figures, axes, lines, surfaces, images, text, menus and other graphics objects. Some of the commands to create graphical objects are:

  • Figure(h) or h = figure create the figure as an object of name h, and is located as a current figure. The gcf(h) (get current handle) command generally means return the handle to the figure. The command close(h) closes figure h. The command whitebg(h) changes the color of the background of the figure h. The command clf closes the current figure. The command graymon is used for legibility of grayscale. The command refresh redraws the figure.
  • axes(e) or e = axes creates the axes as an object of name e, in the current figure. Use the command gca(e) to refer to any property of the e axes. The cla command is used to delete all the objects referring to the current axes.
  • l = line(x,y) or l = line(x, y, z) creates an object of name l, the line joining the points (X, Y) in the flat, or (X, Y, Z) space.
  • p = patch(X, Y, C) or patch(X,Y,Z,C) creates an opaque polygonal area that is defined by the set of points (X, Y) in the flat, or (X, Y, Z) space, and whose color is given by C, as an object of name p.
  • s = surface(X,Y,Z,C) creates the parametric surface defined by X, Y and Z , and whose color is given by C, as an object of named s.
  • i = image(C) creates the image defined by the colors in the array C as an object of name i.
  • t = text(x, y, 'string') or t = text(x, y, z, 'string') creates the text defined by the parameter in single quotes, located at the point in the (x, y) plane, or at the point in the (x, y, z) space.

Each object has a level of hierarchy. The parents of an object are superior in the hierarchy, and children are the objects of a lower hierarchy. The object is created with figure, then, the one created by axes and, finally, and at the same level, are the ones created by image, patch, surface, text and line. This means that if, for example, you want to create a surface, first has to create the figure that is going to be graphed, then the axes, and, finally, the surface itself.

So far we have seen commands that allow you to create objects, but, in addition, all these objects can have properties, as style of line, color, etc. The list of possible properties for each object is very long, and so full knowledge of the list requires consultation of MATLAB Reference manual, http://www.mathworks.com/help/matlab/. As a general rule, the name of a property of an object is a compound word whose components begin with capital letter. For example, the line style property has the name LineStyle. The names of the properties that are mapped by default to an object start with Default, as, for example, DefaultFigureColor, which assigns the color by default to a figure. Below, are some of the most typical properties for the different objects.

Object

Properties

Possible values

Figure

Color (background color)

‘y’, ‘c’, ‘r’, ‘g’, ‘b’, ‘w’, ‘k’

 

ColorMap

hot(p), gray(p), pink(p),....

 

Position

[left, bottom, width, height]

 

Name

string name

 

MinColorMap (min. color no.)

minimum number of colors for map

 

NextPlot (graph mode.)

new, add, replace

 

NumberTitle (No. in the figure)

on, off

 

Units (units of measurement)

pixels, inches, centimeters, points

 

Resize (size figure with mouse)

on (can be changed), off (no)

Axes

Box (box for the chart)

on, off

 

Color (color of the axes)

‘y’, ‘c’, ‘r’, ‘g’, ‘b’, ‘w’, ‘k’

 

GridLineStyle (line for mesh)

‘-’, ‘--’, ‘:’, ‘-.’

 

Position

[left, bottom, width, height]

 

TickLength (length between marks)

a numeric value

 

TickDir (direction of)

in, out

 

Units

pixels, inches, centimeters, points

 

View (view)

[azimuth, elevation]

 

FontAngle (angle of source)

normal, italic, oblique

 

FontName (name of source)

the name of the source font

 

FontSize (font size)

numeric value

 

FontWeight (weight)

light, normal, demi, bold

 

DrawMode (drawing mode)

normal, fast

 

XDir, YDir, ZDir (direction of axes)

normal (growing from left to right), reverse

 

XGrid, YGrid, ZGrid (grids)

on, off

 

XLabel, YLabel, Zlabel (tags)

string containing the text of labels

 

XLim, YLim, ZLim (limit values)

[min, max] (range of variation)

 

XScale, YScale, ZScale (scales)

linear, log (log)

 

XTick,YTick,ZTick

[m1,m2,...] (situation marks on axis)

Line

Color (color of the line)

‘y’, ‘c’, ‘r’, ‘g’, ‘b’, ‘w’, ‘k’

 

LineStyle (line style)

‘-’ , ‘--’ , ‘:’ , ‘-.’ , ‘+’ , ‘*’, ‘.’ , ‘x’

 

LineWidth (line width)

numeric value

 

Visible (visible line or not displayed.)

on, off

 

XData, YData, ZData (coordinates)

set of coordinates of the line

Text

Color (text color)

‘y’, ‘, ‘c’, ‘r’, ‘g’, ‘b’, ‘w’, ‘k’

 

FontAngle (angle of source)

normal, italic, oblique

 

FontName (name of source)

the name of the source font

 

FontSize (font size)

numeric value

 

FontWeight (weight)

light, normal, demi, bold

 

HorizontalAlignment (hor setting.)

left, center, right

 

VerticalAlignment (adjust to vert.)

top, cap, middle, baseline, bottom

 

Position (position on screen)

[x, y, z] (point of situation)

 

Rotation (orientation of the text)

0, ±90, ±180, ±270

 

Units (units of measurement)

pixels, inches, centimeters, points

 

String

the text string

Surface

CData (color of each point)

color matrix

 

EdgeColor (color grids)

‘y’,‘m’,..., none, flat, interp

 

FaceColor (color of the faces)

‘y’,‘m’,..., none, flat, interp

 

LineStyle (line style)

‘-’ , ‘--’ , ‘:’ , ‘-.’ , ‘+’, ‘*’, ‘.’ , ‘x’

 

LineWidth (line width)

numeric value

 

MeshStyle (lines in rows and col.)

row, column, both

 

Visible (visible line or not displayed.)

on, off

 

XData, YData, ZData (coordinates)

set of coordinates of the surface

Patch

CData (color of each point)

color matrix

 

EdgeColor (color of the axes)

‘y’, ‘m’,..., none, flat, interp

 

FaceColor (color of the faces)

‘y’ ,‘m’,..., none, flat, interp

 

LineWidth (line width)

numeric value

 

Visible (visible line or not displayed)

on, off

 

XData, YData, ZData (coordinates)

set of coordinates of the surface

Image

CData (color of each point)

color matrix

 

XData, YData (coordinates)

set of coordinates of the image

Among the commands that allow you to perform operations with graphical objects already created are as follows:

  • set(h, 'propertyname, 'propertyvalue',...) sets the specified properties to the provided values for the object h.
  • get(h, 'property') returns the current value of the specified property of the object h.
  • object = gco returns the current object of the current figure.
  • rotate(h, [a, e], α , [p,q,r]) rotates the object h by the angle α, according to the axis of azimuth, elevation and the origin point (p, q, r) (which is optional, and is the origin point of the axis of rotation, which is the center of the plot if not provided).
  • reset(h) updates all properties assigned to the object h and set its properties to their defaults.
  • delete(h) deletes the object h.

Here are some examples:

The following syntax changes the limits of variation of the current X, Y and Z axes to the specified values:

>> set(gca, 'XLim', [0,10], 'YLim', [-25, 25], 'ZLim', [-8,10])

The following syntax places the color of the background of the current figure in white:

>> set(gcf, 'Color', 'w')

The following syntax returns the current properties for the surface previously created and assigned to the variable named surfh:

>> get(surfh)

The following syntax returns the line style to that of the surface surfh:

>> get(surfh, 'LineStyle')

The following syntax deletes the surface surfh:

>> delete(surfh)

EXERCISE 3-8

Represent coordinates of the following parametric surface:

x(t) = 4cos(r) cos(t),  y(t) = 2sine(r) cos(t),  z (t) = sine(t)   -π< r <π , -π/2 < t <π/2

so that it is presented in a figure with title "Parametric Surface" and whose background color is white, with a black colored axis with the surface itself presented in a grid, colored according to the jet colormap, and enclosed in a cube.

>> r = [-pi:0.1:pi]';
t = [-pi/2:0.1:pi/2];
x = 4*cos(r)*cos(t);
y = 2*sin(r)*cos(t);
z = ones(1,size(r))'*sin(t);
surface = surf(x, y, z);
set(surface,'EdgeColor', interp')
set(gcf, 'Color', 'w', 'Name', 'Parametric Surface'),
set(gca,'XColor', 'k', 'YColor', 'k', 'ZColor', 'k', 'Box', 'on'),

Figure 3-22 represents the ordered surface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset