Game Development Reference
In-Depth Information
Negative Numbers
Another concept that Cartesian
coordinates use is negative numbers.
Negative numbers are numbers that are
smaller than zero. We put a minus sign in
front of a number to show that it is a
negative number. -1 is smaller than 0. And -2
is smaller than -1. And -3 is smaller than -2.
If you think of regular numbers (called
positive numbers ) as starting from 1 and
increasing, you can think of negative
numbers as starting from -1 and decreasing.
0 itself is not positive or negative. In this
picture, you can see the positive numbers
increasing to the right and the negative
numbers decreasing to the left:
Figure 12-2: The same chessboard but with
numeric coordinates for both rows and columns.
Figure 12-3: A number line.
The number line is really useful for doing subtraction and addition with negative
numbers. The expression 4 + 3 can be thought of as the white knight starting at position 4
and moving 3 spaces over to the right (addition means increasing, which is in the right
direction).
Figure 12-4: Moving the white knight to the right adds to the coordinate.
As you can see, the white knight ends up at position 7. This makes sense, because 4 + 3
is 7.
Subtraction can be done by moving the white knight to the left. Subtraction means
decreasing, which is in the left direction. 4 - 6 would be the white knight starting at position
4 and moving 6 spaces to the left:
Search WWH ::




Custom Search