This module is part of the collection, *A First Course in Electrical and Computer Engineering*. The LaTeX source files for this collection were created using an optical character recognition technology, and because of this process there may be more errors than usual. Please contact us if you discover any errors.

**Point Matrix.** To represent a straight-line image in computer memory, we must store a list of all the endpoints of the line segments that comprise the image. If the point

Suppose there are

We then store the point matrix

Consider the list of points

The corresponding point matrix is

**Line Matrix.** The next thing we need to know is which pairs of points
to connect with lines. To store this information for *does not* store line locations directly.
Rather, it contains references to the points stored in

The order of

All the numbers in the line matrix

To specify line segments connecting the four points of Example 1 into a quadrilateral, we use the line matrix

Alternatively, we can specify line segments to form a triangle from the first
three points plus a line from

Figure 1 shows the points

**Demo 1 (MATLAB)**. Use your editor to enter the following MATLAB
function file. Save it as vgraphl.m.

```
function vgraphl (points, lines);
% vgraphl (points, lines) plots the points as *'s and
% connects the points with specified lines. The points
% matrix should be 2xN, and the lines matrix should be 2xM.
% The field of view is preset to (-50,50) on both axes.
%
% Written by Richard T. Behrens, October 1989
%
m=length(lines); % find the number of
% lines.
axis([-50 50 -50 50]) % set the axis scales
axis('square')
plot(points(1,:),points(2,:),'*') % plot the points as *
hold on % keep the points...
for i=i:m % while plotting the
% lines
plot([points(1,lines(1,i)) points(1,lines(2,i))],..
[points(2,lines(2,lines(1,i)) points(2,lines(2,i))],'-')
end
hold off
```

After you have saved the function file, run MATLAB and type the following to enter the point and line matrices. (We begin with the transposes of the matrices to make them easier to enter.)

```
>> G = [
0.6052 -0.4728;
-0.4366 3.5555;
-2.6644 7.9629;
-7.2541 10.7547;
-12.5091 11.5633;
-12.5895 15.1372;
-6.5602 13.7536;
-31.2815 -7.7994;
-38.8314 -9.9874;
-44.0593 -1.1537;
-38.8314 2.5453;
-39.4017 9.4594;
-39.3192 15.0932;
-45.9561 23.4158]
>> G = G'
>> H = [
1 2;
2 3;
3 4;
4 5;
4 7;
5 6;
8 9;
9 10;
10 11;
11 12;
12 13;
12 14]
>> H = H'
```

At this point you should use MATLAB's “save” command to save these matrices to a disk file. Type

`>> save dippers`

After you have saved the matrices, use the function `VGRAPH1`

to draw
the image by typing

`≫ vgraph1(G,H)`

The advantage of storing points and lines separately is that an object
can be moved and scaled by operating only on the point matrix

*Surfaces and Objects.* To describe a surface in three dimensions is a
fairly complex task, especially if the surface is curved. For this reason, we will
be satisfied with points and lines, sometimes visualizing flat surfaces based on
the lines. On the other hand, it is a fairly simple matter to group the points
and lines into distinct *objects*. We can define an object matrix *K* with one
column for each object giving the ranges of points and lines associated with
that object. Each column is defined as

As with the line matrix

Consider again Demo 1. We could group the points in

The first column of

Comments:"Reviewer's Comments: 'I recommend this book as a "required primary textbook." This text attempts to lower the barriers for students that take courses such as Principles of Electrical Engineering, […]"