Damn, this is boring. Bring me back to the Code-Corner!
Table Of Contents
This is a short primer on vector mathematics. I know that there are lots of
vector tutorials out there.
This text is not intendet as a replacement
for a good math-book, but it might be a good reference.
Vector math is important for all kinds of 3d programming. And since this pages
are more or less 3d-related I only deal with 3 dimensional vectors.
Since most browsers still don't support greek and unicode characters it's a little bit
tricky to put them into the text.. I hope that your browser translates them correctly.
My netscape refuses to do so.
How I write my equations:
- Vectors are notated in lower case italic chars (I usually use a, b, c and so on).
- Scalars are notated in lower case chars (non-italic). By the way, if you don't know what a scalar value is: they are the normal, regular number like 24.2 you've ever calculated with before.
Addition and Substraction and Scaling
Addition and Substraction is done on each component on the vector:
Addition:
c = a + b
c.x = a.x + b.x c.y = a.y + b.y c.z = a.z + b.z
c = a - bScaling (Division and Multiplication with a scalar)
c.x = a.x - b.x c.y = a.y - b.y c.z = a.z - b.z
c = a * b
c.x = a.x * b c.y = a.y * b c.z = a.z * b

c = a.x*b.x + a.y*b.y + a.z*b.zIt has two different meanings:

c.x = a.y*b.z - a.z*b.y
c.y = a.x*b.z - a.z*b.y
c.z = a.x*b.y - a.y*b.z
Again the cross-product has several properties:The euclidean length of a vector (we normally only deal with the euclidean length, there are other definitions, but they're not that important) is defined as:
|v| = square_root(v.x² + v.y² + v.z²)Sometimes you hear about a normalized vector. That means, you scale a vector this way, that it's length becomes one.
v'.x = v.x / |v|
v'.y = v.y / |v|
v'.z = v.z / |v|
Of cause this only works if the vector is no null-vector (|v| = 0).
Here are some examples..
a = (10,20,30)
b = (11,12,13)
build a third vector c from a to b:
c = b - a
c.x = b.x - a.x
c.y = b.y - a.y
c.z = b.z - a.z
Calculate the length of c:
distance = |c|
distance = square_root(c.x² + c.y² + c.z²)
u = c-a
v = c-b
The vector perpedicular to u and v is:
n = u x v
Get the normalized vector n' = n / |n| d = n' . a
You can also use the points b or c. It doesn't matter. It's
only important that the point you dot the normal vector with lies on the plane.
| 1 | | 2 | | 1 |
a = | 2 | b = | 3 | c = | 0 |
| 3 | | 4 | | 3 |
| 1-1 | | 0 | | 1-2 | | -1 |
u = | 0-2 | = | -2 | v = | 0-3 | = | -3 |
| 3-3 | | 0 | | 3-4 | | -1 |
| (-2 * -1) - ( 0 * -3) | | 2 - 0 | = | 2 |
n = | ( 0 * -1) - (-1 * 0) | = | 0 - 0 | = | 0 |
| (-2 * -1) - (-3 * 0) | | -2 - 0 | = | -2 |
|n| = sqrt (8)
| 0,707 |
n' = n/|n| = | 0.000 |
| -0,707 |
d = n' . a = ( 0.707 - 2,121) = -1.414
(try dotting with another point (b or c). you sould get -1.414 in all cases)
Equation of the plane is: p . n' - d = 0
All points p that solve this equations lie on the plane.
distance = p . n' -d
This formula has a really great application in 3d graphics. If you already
read my Backface-Culling in Object-Space tutorial you might find this equation
familiar. To be exact: it's the same equation.
As long as I didn't knew what to do with the math I learn at school or in
the university, it was just boring and useless stuff.
But as soon as you can use it, math can be fun.
If you want to contact me you might write me a mail.
And now bring me back to the Code-Corner!