Graphics Reference
In-Depth Information
y
1, 3
x
y
3, 2
1
3
3
1
1
1
2
3
1, 1
3, 1
X
Fig. 5.3. A simple polygon created with four vertices shown in the table.
We can now subject this list of vertex coordinates to a variety of arith-
metic and mathematical operations. For example, if we double the values of
x and y and redraw the vertices, we discover that the form of the shape is
preserved, but its size is doubled with respect to the origin. Similarly, if we
divide the values of x and y by 2, the shape is still preserved, but its size is
halved with respect to the origin. On the other hand, if we add 1 to every
x -coordinate and 2 to every y -coordinate and redraw the vertices, the shape's
size remains the same but it is displaced 1 unit horizontally and 2 units verti-
cally. This arithmetic manipulation of vertices is the basis of shape and object
transformations and is described in Chapter 7.
5.1.4 Areas of Shapes
The area of a polygonal shape is readily calculated from its chain of coordi-
nates. For example, given the following list of coordinates:
xy
x 0
y 0
x 1
y 1
x 2
y 2
x 3
y 3
the area is computed by
1
2 [( x 0 y 1
x 1 y 0 )+( x 1 y 2
x 2 y 1 )+( x 2 y 3
x 3 y 2 )+( x 3 y 0
x 0 y 3 )]
(5.1)
If you check to see what is happening, you will notice that the calculation
sums the results of multiplying an x by the next y , minus the next x by the
current y . When the last vertex is selected it is paired with the first vertex to
complete the process. The result is then halved to reveal the area.
 
Search WWH ::




Custom Search