# Matrices And You, Part 1 : What are they?

## What Are They?

That’s a good question. Here’s the usual 4-dimensional matrix used in 3D, like `TV_3DMATRIX` in TV6.5 :

```| 1   2   3   0 |
| 5   6   7   0 |
| 9   10  11  0 |
| 13  14  15  1 |```

It’s scary. It makes no sense. So let’s take it another way.

First, let’s think of a matrix as a combination of vectors. You know vectors, right? ...right? Alright, let’s take it from there.

## What Really Are Vectors

The intuitive idea about vectors is that they’re a point in space. They’re not.

### Well, what are they?

Vectors are lines in space... well almost. They’re lines without an origin; just a direction and a length.

For example, take this 3D vector here : `V = [ 1 2 3 ]` Don’t like him like that? It can also be expressed like this :

```V = (1, 2, 3)
V = { 1, 2, 3 }
V = | 1  2  3 |
TV_3DVECTOR V = new TV_3DVECTOR(1, 2, 3)```

The important part is that it’s called V, and has three components.

Three components... That’s fairly easy, it’s a 3D vector. One component for each dimension. Since the convention for Direct3D is `X-Y-Z` worlds where `X` is left-to-right, `Y` is bottom-to-top and `Z` is backward-to-forward, that means that `V` has a component of `1` for `X`, `2` for `Y` and `3` for `Z`.

That does not mean that its position in 3D space is `(1, 2, 3)`. It has no position at all. Remember, a line without origin... a force in other words. A difference between two locations, wherever might those two locations be.

A good example vector would be a normal vector. A normal is the vector that pops out of a 3D triangle or a face and that is perpendicular to the surface of this triangle/face. It expresses the orientation of that face, and is used mainly for lighting and physics calculation. Since it only represents the orientation, its position is negligible.

We did mention vectors being a direction and a length. How would we fetch them from `V`?

### Calculating the length and direction of a vector

```Length of V : ||V||
||V|| = Sqrt(V.x² + V.y² + V.z²)

Direction of V : Normalized V
Normalized V = V / ||V||
= V / Sqrt(V.x² + V.y² + V.z²)```

Hope this didn’t scare you too much.

#### What were those symbols?

• Sqrt is the square root operation
• / is the division operator
• ||x|| is just a notation for the length of a vector
• ² is the square... x * x

#### Why this square root of the sum of the squares of the three components?

• This is the pythagorean theorem, a pretty simple theorem to express the length of a line (`V`) if we know its separate components (`x, y` and `z`)... which we do. The length is then a single number.

#### And why would we divide the vector by the length, and what's a vector divided by a single number anyway?

• If we take the vector and divide it by its length, and calculate the length of the resulting vector, it will always be `1`. This is the definition of a normalized vector; a vector whose length is `1`. It can also be called a unit vector.
• A vector multiplied or divided by a single value, like the length here, will multiply or divide each of components by this value.

### What does this have to do with anything?

Once we know all of that terminology, we can start expressing matrices as vector arrays. Which is covered in part two, actually.