logo back up home forward   further reading more topics »

Maths - Vectors

Like many mathematical concepts, vectors can be understood and investigated in different ways.

There are two main complimentary ways to look at vectors:

The algebraic approach and its operations are explained on this page.

Vectors connect all the main branches of mathematics: algebra, geometry and calculus. This connection can be made by representing the vector as a linier combination of basis vectors. In geometric terms, we must always return to a real physical vector in the end, other vectors are derived in terms of these. In algebraic terms we can combine together the scalar multipliers of the basis vectors and treat this set of numbers as the object of vector algebra.

The vector may be shown as a single column:

5.6
9.3
3.5
7.0

or as a row:

8.4 1.8 5.5 6.2

Relationship to other mathematical quantities

We could think of vectors in other ways, for instance:

Vectors are strongly related to matrices, they can be considered as a one directional matrix, or conversely, we could construct a matrix from a vector (drawn as a column) whose elements are themselves vectors (drawn as a row) :

6 1 7 5
8 4 4 2
2 0 6 9
1 3 0 3

Strictly I don't think a matrix is a vector of vectors? Because the dot product converts from a vector to a scalar. With matrix multiplication each element is the dot product of a row from one matrix and the column from the other matrix (see matrix arithmetic) Perhaps it would work if the second matrix to be multiplied were transposed first? Can anyone help me work this through.

Regardless of whether we consider vectors as a special case of matrices, or matrices as vectors of vectors, or if we consider vectors and matrices as different types, using vectors and matrices together is very important. A matrix is a way to transform one vector into another vector (and a whole set of vectors into another set of vectors). This allows us to express a linear transform as a single equation:

Vout 0
Vout 1
Vout 2
Vout 3
=
m00 m01 m02 m03
m10 m11 m12 m13
m20 m21 m22 m23
m30 m31 m32 m33
Vin 0
Vin 1
Vin 2
Vin 3

See also 'alternative interpretation of vectors' below.

Relating the Algebraic and Geometric interpretation of vectors

On this page we discuss the algebra of vectors including the addition, subtraction and multiplication operations.

On this page we discuss the geometric interpretation of these operations.

Is there a way to understand the properties of geometric (Euclidean) space purely in terms of its algebraic properties? In other words, to link the geometric and algebraic properties discussed already?

linearity of space

One property is the linearity of space, a function L : U -> V between two linear spaces U and V is said to be linear if for any a, b in U and s in Real:

The first of these relates to vector addition, which has the following properties:

a + b = b+ a commutivity
(a + b) + c = a + (b + c) associativity
a + 0 = a identity vector 0
a + (- a) = 0 opposite vector -a

the second relates to scalar multiplication which has the following properties:

s (a + b) = s a + s b distributivity
(s1 + s2) a = s1 a + s2 a distributivity
(s1 s2) a = s1 (s2 a) associativity
1 a = a identity scalar

Vectors can be multiplied by scalars even though they are separate entities, vectors and scalars can't be added for instance (not until we get to clifford algebra), but we can define a type of multiplication called scalar multiplication usually denoted by '*' or the scalar may be written next to the vector with the multiplication implied. This type of multiplication takes one vector and one scalar. Scalar multiplication multiplies the magnitude of the vector, but does not change its direction, so:

if we have,

vOut = 2*vIn

where:

then, vOut will be twice the magnitude of vIn but in the same direction.

Quadratic structure on a linear space

However these linear properties are not enough, on their own, to define the properties of Euclidean space using algebra alone. To be able to define concepts like distance and angle we must define a quadratic structure.

For instance pythagoras:

r2 = x2 + y2 + z2

in algebraic terms,

if a is a three dimentional vector with bases e1, e2, e3

a = a1 e1 + a2 e2 + a3 e3

so,

a•a = a12 + a22 + a32

Other Vector Algebras

In the vector algebra discussed already the square of a vector is always a positive number:

a x a = 0
a • a = positive scalar number

However, we could define an equally valid and consistent vector algebra which squares to a negative number:

a x a = 0
a • a = negative scalar number

We could also define an algebra where we mix the dimensions, some square to positive, some square to negative. An example of this is Einsteinean space-time, space and time dimensions square to different values, if space squares to positive then time squares to negative and visa-versa.

Applications of Vectors

For 3D programming (the subject matter of this site) we are mainly concerned with vectors of 2 or 3 numbers.

A vector of dimension 3 can represent a physical quantity which is directional such as position, velocity , acceleration, force, momentum, etc.

For example if the vector represents a point in space, these 3 numbers represent the position in the x, y and z coordinates (see coordinate systems). Where x, y and z are mutually perpendicular axis in some agreed direction and units.

A 3 dimensional vector may also represent a displacement in space, such as a translation in some direction. In the case of the Java Vecmath library these are two classes: Point3f and Vector3f both derived from Tuple3f. (Note these use floating point numbers, there are also classes, ending in d, which contain double values). The Point3f class is used to represent absolute points and the Vector3f class represents displacement. In most cases the behavior of these classes is the same, as far as I know the difference between these classes is when they are transformed by a matrix Point3f will be translated by the matrix but Vector3f wont.

Here we are developing the following classes to hold a vector and encapsulate the operations described here,

It would be possible to build a vector class that could hold a vector of any dimension but a variable dimension class would be less efficient. Since we are concerned with objects in 3D space it is more important to handle 2D and 3D vectors efficiently.

Vector Notation

On these pages we put an arrow above a variable to show that it is a vector:

If we want to show the individual values of the vector we can use the following notation:

Where:

Or an alternative we can use the following notation:

= x i + y j + z k

Where:

The first form is more convenient when working with matrices, whereas the second form is easier to write in text form.

Other vector quantities

Alternative interpretation of vectors

Upto now we have thought of the vector as the position on a 2,3 or n dimensional grid. However for some physical situations there may not be a ready defined Cartesian coordinate system. An alternative might be to represent the vector as a linear combination of 3 basis:

σ1
σ2
σ3

These basis don't have to be mutually perpendicular (although in most cases they probably will be) however they do have to be independent of each other, in other words they should not be parallel to each other and all 3 should not be in the same plane.

So a vector in 3 dimensions can be represented by [a,b,c] where a,b and c represent the scaling of the 3 basis to make the vector as follows:

a σ1 + b σ2 + c σ3

Note that if this vector represents position then it will be a relative position, i.e. relative to some other point, if we want to define an absolute point we still have to define an origin.

So the problem remains of how to define the basis, there may be some natural definition of these in the problem domain. Alternatively we could define the basis themselves as 3D vectors using a coordinate system. But why bother to do this, if we have a coordinate system why not just represent the vectors in this coordinate system? Well we might want to change coordinate systems or translate all the vectors in some way (see here). For example, we might want to represent points on a solid object in some local coordinate system, but the solid object may itself be moving relative to some absolute coordinate system.

Further Reading

Vectors can be manipulated by matrices, for example translated, rotated, scaled, reflected.

There are mathematical objects known a multivectors, these can be used to do many of the jobs that vectors do, but they don't have some of the limitations (for example vector cross product is limited to 3 dimensions and does not have an inverse).


metadata block
see also:
Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Introduction to 3D Game Programming with DirectX 9.0 - This is quite a small book but it has good concise information with subjects like, maths introduction and picking.

cover Mathematics for 3D game Programming - Includes introduction to Vectors, Matrices, Transforms and Trigonometry. (But no euler angles or quaternions). Also includes ray tracing and some linear & rotational physics also collision detection (but not collision response).

Other Math Books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

 

cover Dark Basic Professional Edition - It is better to get this professional edition

cover This is a version of basic designed for building games, for example to rotate a cube you might do the following:
make object cube 1,100
for x=1 to 360
rotate object 1,x,x,0
next x

cover Game Programming with Darkbasic - book for above software

Can you help?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

Terminology and Notation

Specific to this page here:

 

program

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

http://sourceforge.net/projects/mjbworld/

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2008 Martin John Baker - All rights reserved - privacy policy.