To see how this works, let's review some basic operations on vectors. The addition of two vectors can be shown graphically. It works as might be expected: Two vectors and add up to . Here is how it looks in a graph:
Notice how the first vector starts from the origin (0,0). The second vector is then placed with its tail (the end with no arrow head) to the head of the first. The combination of the two is the same as a vector starting from the origin connecting to the head of the second one. Subtraction follows in a similar fashion, but reverses the direction of the second vector.
Graphing addition like this, a collection of vectors (each representing a line) can be used to create basic images, a vector version of connect-the-dots. Although our example is simple in nature, many vectors can be combined to generate complex drawings.
Let's try an example to illustrate what can be done. Following is a complete Python program that uses both the Numeric (NumPy) module as well as pxDislin. What is new from last month is the use of the
dMultiLine function, which draws a line (vector) between points of
y_list arguments. Essentially, the dMultiLine function is performing a vector addition operation. The function does not actually do the math, but it does graphically represent the operation. The points chosen trace out a simple box structure of a house centered on the plot axis.
from pxDislin import * from Numeric import * plot = dPlot() axis = dAxis(-20,20,-20,20) plot.add_axis(axis) house_pts = array([[5,5,-5,-5,5,4,4,2,2,5,5,0,-5], [-5,5,5,-5,-5,-5,-1,-1,-5,-5,5,8,5]]) house = dMultiLine(house_pts,house_pts) plot.add_object(house) plot.show()
The generated plot is:
The points that draw out the house are essentially a 2-by-13 matrix:
where the x coordinates are in the top row and the y coordinates are the bottom row. Each column of the matrix may be taken as a 2-by-1 vector, and as such the matrix is a collection of 13 column vectors.