Wednesday, 1 October 2008

matrices and vectors and positions

A 3 dimensional vector has three components: x,y,z
It specifies a direction and a magnitude.
You can use it to describe a velocity, a direction (if it's unit), an acceleration, momentum, displacement between two positions, and angular velocity (using magnitude and direction), but you can never use it as a position.

A 3 dimensional positoin has thre components: x,y,z
It specifies where in space a point exists.
You can use it for the position of a vertex, the centre of a sphere/circle/shape, the target of a camera, but you can never use it as a vector.

Why so strict?

A vector is usually defined by having it's w value set to 0 and a position equally by a w of 1.
This means that to do any mathematics with these two constructs, you must follow some simple rules that can be found out by trying out the maths on the four element vector:

1. a position can never be added to another position
2. the difference between two positions is a vector (displacement)
3. the sum of a position and a vector is a position
4. the sum of two vectors is a vector
5. you cannot dot product a position with anything
6. you cannot multiply a position by a scalar

okay, so vectors point, and positions place...

And a matrix is made of three vectors telling you which way each of the matrices axis point, and a position to tell you where in space it is.

don't beleive me?

a matrix is really

x2x, x2y, x2z, 02w
y2x, y2y, y2z, 02w
z2x, z2y, z2z, 02w
w2x, w2y, w2z, w2w

which means any vectors (with w of 0) will be transformed by just the rotation part...
and any positions (with a w of 1) will be transformed, then have the position added...

which is right if you think about it for a moment.

so... time to typesafe your math library yet and save cycles while still behaving like a full matrix transform library?

No comments: