# Chapter 7: Vectors

## Basics

A 2D point:

represents a location w/ respect to some coordinate system.

A 2D vector:

represents a displacement from a position.

Vectors have length and direction - but no inherent location. Can represent a displacement or motion.

Consider that one step north while standing in NYC is the same as one step north while standing in SLO - in terms of displacement/motion.

### Notation

We write vectors as lists of components: ${ x_0, x_1 }$

We write vectors as a column matrix:

## Operations

### Scalar

Multiplication by a scalar:

Multiplying a vector by a scalar changes its length, but not its direction.

(this is component-wise)

### Subtraction

Geometric of $- \vec v$ is a vector in the opposite direction.

So, subtraction is not suprising:

## Basis Vectors

### Linear Combination

A linear combination of $m$ vectors $v_1, v_2, ..., v_m$ is a vector of the form:

where $a_1, a_2, ..., a_m$ are scalars.

Barycentric coordinates are an example of a linear combination (of $3$ vectors).

### Linearly Independant

If two vectors are non-zero and not parallel, they are called linearly independant.

For two given linearly independant vectors $\vec v_1$ and $\vec v_2$, we can write any vector $\vec v_3$ in terms of the other two.

The two vectors $\vec v_1$ and $\vec v_2$ are then called basis vectors.

Any vector can be expressed as a linear combination of the basis vectors:

Note that the cooeficients $a_c$ and $b_c$ are unique - that is, a different $a_c$ and $b_c$ will give a different vector $c$.

## Cartesian Coordinates

If two vectors are at right angles to each other (e.g. they are orthogonal), they form an orthogonal basis.

If the vectors are also both of length $1$, we call this an orthonormal basis.

In 2D, we can use 2 such special vectors $\vec x$ and $\vec y$ to define the Cartesian basis vectors:

Not surprisingly, the Cartesian basis vectors in 3D are:

(Note that for a 3D coordinate system, we need three basis vectors.)

### Handedness

Depending on where the $z$ axis points, we call a basis left or right handed. This will come up again when we talk about other operations on vectors.

The handedness refers to how the third basis is related to the first two. If the first basis vector is along your thumb and the second basis vector is along your index finger, your palm is pointing in the direction of the third basis vector. Note that this is a different direction for your left or right hand.

In OpenGL, we use a right-handed basis.

## Coordinate Frame

A Coordinate Frame (or coordinate system) consists of an origin point $o$ ${0, 0, 0}$ and a basis of linearly independant vectors $\vec a, \vec b, \vec c$.

The standard coordinate system in 3D is:

Any 3D point ${q, r, s}$ can be written as: