where the x, y, and z are the coordinates of the points on the surface. The function surf draws a surface composed of colored patches, whereas mesh draws
white surface patches that are defined by their boundary. In surf, the colors of
the patches are dete
Section 7.1
7.1 Plot the following three-dimensional curves. Use axis equal.
Name
Parameter values
Equations
Spherical
helix6
c = 5.0; 0 w 10p
x = sin(w/2c) cosw
y = sin(w/2c) sinw
z = cos(w/2c)
Toroidal
spiral
a = 0.2, b = 0.8,
c = 20.0; 0 w 2p
x = [b +
368
Chapter 7
3D Graphics
hold on
mesh(Xr, Yr, Zr)
text(0.5, -0.5, 1,'\phi = 60\circ')
case 3
psi = pi/3; chi = 0; phi = 0;
[Xr Yr Zr] = EulerAngles(psi,chi,phi,Lx,Ly,Lz,X,Y,Z);
mesh(X, Y, Z)
hold on
mesh(Xr, Yr, Zr)
text(0.5,-0.5,1,'\psi = 60\circ')
case
7.3 SUMMARY OF FUNCTIONS INTRODUCED IN CHAPTER 7
In Table 7.10, we have summarized the plotting functions introduced in Chapter 7.
TABLE 7.10 MATLAB Functions Introduced in Chapter 7
MATLAB function
Description
axis on/off
box on/off
Turns axes on and off
We now illustrate the use of these transformation equations with the manipulation of a torus, whose coordinates are given by5
x = r cosu
y = r sinu
z = ; 4a 2 -
A 2x2 + y2 - b B 2
where b - a r b + a, 0 u 2p, and b 7 a.
We first create the following funct
[x, y, z, L] = PlanarSurface([0 0 0], [2 6 3], [7 1 5]);
surf(x, y, z)
PlanarSurfaceProj([0 0 0], [2 6 3], [7 1 5])
we obtain the results shown in Figure 7.11. Although there is an illusion that the projections do not appear to be in their designated plan
and for the projection onto the xz-plane
P # (i + 0j + k)
Thus, we create a new function M file PlanarSurfaceProj to obtain these
projections.
function PlanarSurfaceProj(P0, P1, P2)
[xx, yy, zz, L] = PlanarSurface(P0, P1, P2);
hold on
a = axis;
c(1:L, 1:L
equal to 2a, minor axis in the y-direction equal to 2b, and minor axis in the z-direction
equal to 2c, the ratio of the volume of an ellipsoid to the volume of a sphere is
given by
V =
Vellipse
Vsphere
= a
b
c
ba b
a
a
We create the following program to e
S = 0:0.2:1;
L = length(S);
[s, t] = meshgrid(S, S);
xx = P0(1)+s*v(1)+t*w(1);
yy = P0(2)+s*v(2)+t*w(2);
zz = P0(3)+s*v(3)+t*w(3);
where P0, P1, and P2 are each three-element vectors containing the coordinates of the
points on the plane. Thus, if we execu
Name
Parameter values
Equations
Hyperbolic
helicoid17
t = 7; -p u p,
0 v 0.5
x =
Apple
surface18
0 u 2p, -p v p
[Use the transparency option
to view interior]
sinh(v) cos(tu)
1 + cosh(u) cosh(v)
sinh(v) sin(tu)
y =
1 + cosh(u) cosh(v)
sinh(u) cosh(v)
z =
7.2 Plot the following surfaces. Use axis equal vis3d. Use the Rotate 3D icon to get a better understanding of the surface. In some cases, the use of shading interp will improve
the image.
Name
Parameter values
Equations
Seashell11
0 v 2p, 0 u 6p
x = 2 A
k
ck = cumsum(f)
where f = [f1 f2 fk] = [n1/n n2/n nk/n]. We can also plot ck versus bk , which is
an approximation to the probability that a measurement has a value less than or
equal to bk .
Now let us sort x from its lowest value to its highest value.
and sample variance is
n
1
c a x2 - nx2 d
q
n - 1 j=1 j
s2 =
(8.2)
where s is the standard deviation. These quantities are the estimates of the true
mean m and the true standard deviation s. The mean value is determined from
mean(x)
and the standard devia
7.9 Consider a thin rectangular plate with a circular hole of radius a that is subjected to a
uniform tension of magnitude S in the x-direction. The radial, tangential, and shear
stresses are, respectively, given by23
srr =
srr
1
3
4
= 1 - 2 + a 1 + 4 - 2
7.5 Plot the following mode shape and its contours for a square membrane clamped on its
outer boundary using twenty-five grid points in each direction for 0 x 1 and
0 y 1:
w23(x, y) = sin(2px) sin(3py)
7.6 The mean Nusselt number for turbulent flow over a
Four additional ways to visually enhance the surface generated by SurfExample
are illustrated in Table 7.4.
Contour Plots
Surfaces can also be transformed into various contour plots, which are plots of the
curves formed by the intersection of the surface
TABLE 7.2 Continued
Plotting function
Script
Graph
box on
axis on
grid off
[x, y, z] = SurfExample;
mesh(x, y, z)
box on
axis on
grid off
200
150
100
50
0
15
10
4
2
5
0
0
2
5
4
As mentioned previously, the colors of the patches are generated automatically
Reversing One Axis
The portions of the disc, lines, and surface that were not visible in Figure 7.4a can be
viewed by reversing one of the display axes. This reversal is implemented with
axis ij
When this command is appended to SurfDisc and the program ru
zc = xc.^4+3*xc.^2-2*xc+6-2*yc.*xc.^2+yc.^2-2*yc;
hold on
plot3([xc; xc], [yc; yc], [zeros(1, 4); zc], 'k-')
function Disc(R, zo)
r = linspace(0, R, 12);
theta = linspace(0, 2*pi, 50);
x = cos(theta')*r;
y = 5 + sin(theta')*r;
hold on
z = repmat(zo, size(
Section 7.2
Surfaces
343
TABLE 7.1 Illustration of the Difference between surf, mesh, and mesh without Hidden Line Removal
Plotting function
Script
surf
Graph
[x, y, z] = SurfExample;
surf(x, y, z)
200
150
100
50
0
15
10
4
2
5
0
0
2
5
mesh
4
[x, y, z] = S
increments in the circumferential direction. The script to plot a cylindrical surface
with this profile is
zz = linspace(0, 2*pi, 26);
[x, y, z] = cylinder(1.1+sin(zz), 16);
surf(x, y, z)
axis off
which upon execution gives the results shown in Figure 7.5