## 2. The underlying mathematics

The basic idea behind homogeneous coordinates is to use a
triple `(x,y,W)`

to represent a
point `(x,y)`

, where
`W`

is any nonzero value. Refer
to Foley and van Dam's book for the reasoning. Here we
will concern ourselves only with the mechanics.

To convert a regular Cartesian coordinate pair `(x,y)`

into a triple, just use `W=1`

. So, for example, point (3.4, -2.2) is
represented as the triple (3.4, -2.2, 1.0).

The various transformations may yield triples whose
`W`

value is not 1.0. To convert such a
triple back to Cartesian coordinates, divide through by the
W value, so the result is `(x/W, y/W)`

in Cartesian space. Clearly, we do not allow `W=0`

.

All coordinate transformations can be represented as a
combination of these three basic transforms:

Translation: Add a constant offset `d`_{x}

to all
`x`

coordinates, and another
constant offset `d`_{y}

to all `y`

coordinates.

Scaling: Multiply each `x`

coordinate by a constant `s`_{x}

; multiply each
`y`

by a (possibly
different) constant `s`_{y}

.

Rotation: Rotate the figure around the origin. In a polar
coordinate system with the same origin, this
means that all the θ values change by the same
amount, but no `r`

values
change.

Each of the above transformations can be represented as a
matrix operation. Let a point `P`

be represented by a 3-element vector `(x,y,W)`

. Then the transformed point
`P'`

is given by:

Here are the transform matrices for the three basic
transformations. `T`_{d}

is a translation by the addition of
`d`_{x}

to
`x`

and the addition of
`d`_{y}

to
`y`

.

Scaling, multiplying each `x`

value by `s`_{x}

, and multiplying each `y`

value by `s`_{y}

:

Rotation by an angle θ: