Page 177 - Basics of MATLAB and Beyond
P. 177
The matlab code to draw the triangular pyramid using these matrices
is
vertices_mx = [ 0 0 0
.5 1 0
1 0 0
.5 .5 1];
faces_mx = [1 2 3 % base
1 2 4
2 3 4 % Face ‘A’
1 3 4]; 1
clf 0.5
z
patch(’Vertices’,vertices_mx,...
0
0
’faces’,faces_mx,’FaceColor’,’y’)
0.5
view(162,44) 0
0.5
box;xyz y 1 1 x
When drawing three dimensional objects, beware of intersecting patches.
Each patch is drawn in its entirety, so intersecting patches often look
strange. For example, here are two triangles that intersect along their
symmetry axes:
vert = [0 0 0
1 1 0
1-1 0
1 0 -1
1 0 1];
fac=[123
1
1 4 5];
clf z 0
patch(’vertices’,vert,... −1
1
’faces’,fac,’facecolor’,’y’) 1
0
0.5
view(3),grid,xyz y −1 0 x
Explore this graphic by typing rotate3d and moving the viewpoint with
the mouse. You should see that you never get a realistic image. A better
way to create the required display is to generate four nonintersecting
triangles:
vert2 = [0 0 0
1 1 0
1-1 0
1 0 -1
1 0 1
1 0 0];
c 2000 by CRC Press LLC

