Vector Fundamentals
Page 1 of 5
<1 | 2 | 3 | 4 | 5>
Single-page view
Vector Fundamentals

Geometry plays a central role in game programming, underlying not only graphics, but also physics and spatial AI. A lot has happened since geometry was first formalised by the Greeks more than two thousand years ago, most notably the invention of coordinates and vectors. These inventions are indispensible for doing geometry on machines (at least, the kind of geometry that is useful for games).

This article introduces the basic concepts of vectors. In a following article, we will look at how vectors can be used to solve geometric problems that arise in computer graphics, physics and AI.

Introduction

(I am assuming here that you already know about coordinates, axes and points; if you don't, check out this link.)

A vector specifies the relationship between two points; in essence, it says how to get from point A to point B.

Suppose point A is given by the coordinates (ax,ay), and B is given by the coordinates (bx, by). Then the vector from A to B is defined as [bx - ax,by - ay]. The two values are called the components or sometimes the coordinates of the vector. We can use a variable v to denote a vector; vectors are sometimes printed with an over-bar (Equation) or arrow (Equation).

Examples

Table 1 - Vectors

Notice that even though the first two examples have different pairs of points, the same vector results. Vectors at different positions are the same as long as the vector components are the same. This is convenient when we draw pictures – we can translate the vector everywhere, without changing it.

In the last example, the vector from the origin has the same coordinates as the point B. This useful fact makes it possible to drop the distinction between points and vectors – we always think of a point as a vector with the same coordinates. For the remainder of this article, when I say point A, I really mean the vector from the origin to point A.

When we operate with vectors, an operand or result that is not a vector is referred to as a scalar. A scalar is simply a real number; the terminology is useful to distinguish it from a vector component.

In this article, we will use letters

  • u, v, and w for vectors (with components vx , vy , etc.);
  • a and b for scalars; and
  • α for angles.



Words from the readers
Hi J Frew,

Don't worry, code will follow in the next article. The math is important to follow such code, write your own code, optimize it, and solve problems on paper before implementing solutions on computer. Have a look out for the next article in this series, though!

ht
Posted by Herman at 13:30:08 on 13 August 2009
Pity this article dissolves into a maths text as opposed to a programmers reference, next time use some sort of code to explain the formulae please. Implementation is far more important to myself than mathematical formulae.
Posted by J Frew at 12:54:52 on 13 August 2009
Have your say: