An affine is a transformation
matrix made up of six real numbers that can be applied to an ordered pair. Depending on
the contents of the affine, the point it is applied to
can be:
Conceptually, an affine defines a relationship between
points on a plane. For any point (A,B), the affine
defines a single corresponding transformed point; the
mapping is onetoone, so given the transformed point you
can determine the original point.
Affines have interesting properties that make them useful
in computer graphics. Most importantly, they can be composed,
concatenated, or multiplied
(the three terms are synonymous). You can compose any
number of affines to create a single affine; applying the
single affine has the same effect as applying each of the
original affines in order. Note that the order of
composition is important! Unlike multiplication, affine
composition is not commutative (which is a reason to
avoid the term "multiply" in this context).
libart_lgpl contains a
module for affine manipulation. It represents affines as
an array of six doubles. Its affine functions are shown
in Figure 3.
art_affine_point() applies an
affine to a point. The affine is applied to the second
argument (src) and the
result is copied into the first argument (dst). An
ArtPoint is simply:
typedef struct _ArtPoint ArtPoint;
struct _ArtPoint {
double x, y;
};

Affines can be inverted. If an
affine converts points in coordinate system A into points
in coordinate system B, its inverse converts points in
coordinate system B into points in coordinate system A.
art_affine_invert() fills its
first argument with the inverse of its second.
art_affine_multiply() composes
two affines as described earlier in this section, placing
the result in its first argument.
Four functions are provided to create affines with
particular properties.

art_affine_identity()
creates the identity affine. Applying the identity
affine to a point has no effect.

art_affine_rotate() gives
an affine that rotates points by theta degrees.

art_affine_translate()
gives an affine that translates points tx in the X dimension and ty in the Y dimension.

art_affine_scale() gives an
affine which scales the plane by the given factors (a
factor of 1.0 does no scaling, less than 1.0 shrinks,
greater than 1.0 expands).
art_affine_rectilinear()
returns TRUE if the
affine rotates rectangles aligned to the axes in such a
way that they remain aligned to the axes. That is, it
returns TRUE if the
rotation is 0, 90, 180, or 270 degrees.
You can ask the canvas widget to compute affines which
convert between its various coordinate systems. These
functions are shown in Figure 4; each of them
fills an array you pass in with the affine being
requested.