Game Development Reference
In-Depth Information
Figure 3.2 The 2D vector 1, 2 drawn with its tail at the origin and its head
“pointing at” (1, 2).
Several basic operations can be performed on a vector. It is valuable to know the
arithmetic of how to calculate these operations, but it is far more useful to un-
derstand the geometric implications of them. That's because this geometric under-
standing is what will enable vectors to solve problems when you're programming
a game.
In the subsequent sections, we cover the most common vector operations. Note
that although the diagrams are mostly in 2D, unless otherwise noted all operations
work on both 2D and 3D vectors.
Addition
To add two vectors together, each component is individually added to the corres-
ponding component of the other vector:
For the geometric representation of addition, draw the vectors such that the head
of one vector touches the tail of the other vector. The result of the addition is the
vector drawn from the tail of the first vector to the head of the second vector, as
shown in Figure 3.3 .
Search WWH ::




Custom Search