This article is part 1 in the series about transformation matrices:
- Part 1: Coordinate systems and transformations between them (this article)
- Part 2: Scaling objects with a transformation matrix
- Part 3: Shearing objects with a transformation matrix
- Part 4: Translating objects with a transformation matrix
- Part 5: Combining Matrix Transformations
World space1, upright space, object space
why bother having multiple spaces?
Information is given only in the context of a particular reference frame
- world space: global reference frame
- the position of other coordinates spaces can be expressed in terms of this space
- this space cannot be expressed in terms of any larger/outer space
- note that there’s no “absolute” space however this space is the largest one we care about
- object space: space associated with each object that belongs to the world space
- camera space: object space associated with the viewport used for rendering
- upright space: special space associated with each object, it’s halfway between world space and object space in the sense that the axes of this space are parallel to the ones of the world space but the origin of this space is coincident with the origin of the object space
Why do we have an upright space?
Thanks to this space the problem of transforming a point between object space -> world space (and vice-versa) can be divided in two subproblems
- object space -> upright space (a rotation)
- upright space -> world space (a change of location)
Coordinates of a vector
A coordinate system consists of
- an origin (displacement from another coordinate system origin)
- a basis (a set of three vectors)
The numeric coordinates of a vector expressed with respect to some basis are the coefficients of the representation of the vector as a linear combination of the basis
In other words the numeric coordinates are the quantities that multiply each basis vector which are $v_x$, $v_y$ and $v_z$
When the basis vectors are $\mathbf{i} = [1, 0, 0]$, $\mathbf{j} = [0, 1, 0]$ and $\mathbf{k} = [0, 0, 1]$ then
Transformations between space coordinates
From object space to upright space
Let $\mathbf{v}$ be some vector expressed/measured relative to a space (object space) whose basis vectors are $\mathbf{p}, \mathbf{q}, \mathbf{r}$ (which are themselves expressed/measured relative to a wrapper space), the vector $\mathbf{v}$ expressed relative to the wrapper space is
Note that if $\mathbf{p}, \mathbf{q}, \mathbf{r}$ were not orthogonal then $\mathbf{v}_{upright}$ couldn’t be uniquely determined
The coordinates of $\mathbf{p}, \mathbf{q}, \mathbf{r}$ are always equal to $[1, 0, 0], [0, 1, 0]$ and $[0, 0, 1]$ respectively when expressed using the coordinate system for which they are the basis, relative to other wrapper coordinate systems they will have arbitrary coordinates
From upright space to world space
Since the axes of the upright space are parallel to the axes of the world space the only difference between these spaces is the translation of these axes with respect to the origin of the axes of the world space, let $\mathbf{o}$ be the translation of the upright basis axes then
From world space to upright space
We just have to translate the whole space so that the origin lies exactly on the origin of the upright space, if $\mathbf{o}$ is the origin of the upright space expressed in world space then
From upright space to object space
What if $\mathbf{v}_{upright}$ is known and we want to know $\mathbf{v}$? The dot product is the key as it’s used to measure distance in a particular direction, since we know that the basis vectors $\mathbf{p}, \mathbf{q}, \mathbf{r}$ are expressed in terms of the upright space perspective we just have to calculate the projection of $\mathbf{v}_{upright}$ in the direction of each $\mathbf{p}, \mathbf{q}, \mathbf{r}$
If we use \eqref{object-upright} this works because the dot product with $\mathbf{p}$ will isolate the $v_x$ coordinate
Note: this only works when $\mathbf{p}, \mathbf{q}, \mathbf{r}$ are orthonormal, for the general case we have to solve this using linear algebra
-
words like “coordinate system”, “coordinate frame” or “space” are used interchangeably ↩︎