ARTICLES

# Coordinate systems

Let \(\vec{v}\) be a vector on a plane. Let’s assume that there exist two other vectors \(\vec{i}\) and \(\vec{j}\) on the same plane such that we can express \(\vec{v}\) as:

$$ \vec{v} = x \vec{i} + y \vec{j} $$

Where \(x, y \in \mathbb{R} \).

In such a scenario, we can call the ordered list \((\vec{i}, \vec{j})\) a
*coordinate system* for the plane and we call the pair \((x, y)\) the
*coordinates* of \(\vec{v}\) in that coordinate system.

Most if not all geometrical concepts can be perfectly understood and analyzed without resorting to picking one of the infinite, arbitrary coordinate systems.

With that said, there are a few things that are easier using coordinates,
provided that you chose a *“nice”* coordinate system. By *“nice”* we mean
coordinate systems made of vectors whose length is \(1\) and that are at
right angles between each other. We call such coordinate systems
*orthonormal coordinate systems*.

## Length of a vector

Let’s pick an orthonormal coordinate system \((\vec{i}, \vec{j})\) on a plane.

By the Pythagorean theorem, the length \(v\) of a vector on a plane \(\vec{v}\) with coordinates \((x, y)\) is given by:

$$ v = \sqrt{x^2 + y^2} $$

This is also true in a space for a vector \(\vec{v}\) with coordinates \((x, y, z)\) according to some orthonormal coordinate system \((\vec{i}, \vec{j}, \vec{k})\):

$$ v = \sqrt{x^2 + y^2 + z^2} $$

## Angle between two vectors

Let’s choose an orthonormal coordinate system \((\vec{i}, \vec{j})\) on a plane. Let’s take two unit length vectors \(\vec{u}\) and \(\vec{v}\) with coordinates \((x_u, y_u)\) and \((x_v, y_v)\) respectively.

The tip of such vectors must lie on a circle with radius \(1\) centered on the origin. Let’s call:

- \(\alpha\) the angle, in radians, between \(\vec{i}\) and \(\vec{u}\);
- \(\beta\) the angle, in radians, between \(\vec{i}\) and \(\vec{v}\);
- \(\theta\) the angle, in radians, between \(\vec{u}\) and \(\vec{v}\).

Then we must have:

$$ x_u = \cos{\alpha} ~~~~~~~~ y_u = \sin{\alpha} ~~~~~~~~ x_v = \cos{\beta} ~~~~~~~~ y_v = \sin{\beta} $$

Now let’s consider the quantity \((x_u, y_u) \cdot (x_v, y_v)\) defined as follows:

$$ (x_u, y_u) \cdot (x_v, y_v) := x_u x_v + y_u y_v $$

Let’s substitute the trigonometric expressions for those coordinates:

$$ = \cos{\alpha} \cos{\beta} + \sin{\alpha} \sin{\beta} $$

By using the difference formula for the cosine we can write:

$$ = \cos(\alpha - \beta) $$

Since the cosine is an even function we can write:

$$ = \cos(\beta - \alpha) $$

Since \(\beta - \alpha\) is \(\theta\), we just proved that:

$$ (x_u, y_u) \cdot (x_v, y_v) = \cos(\theta) $$

Most languages and libraries for geometrical computation have a primitive for computing
this quantity, which goes under the name of *dot product*. For instance,
GLSL has the `dot`

function.