Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Gtk+/Gnome Application Development
Prev Home Next

Affine Transformations

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:

  • translated---shifted by an arbitrary distance in either dimension;

  • rotated some number of degrees;

  • scaled by some factor.

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 one-to-one, 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.

       #include <libart_lgpl/art_affine.h>

void art_affine_point(ArtPoint* dst, const ArtPoint* src, const double affine[6]);

void art_affine_invert(double dst_affine[6], const double src_affine[6]);

void art_affine_multiply(double dst[6], const double src1[6], const double src2[6]);

void art_affine_identity(double dst[6]);

void art_affine_scale(double dst[6], double sx, double sy);

void art_affine_rotate(double dst[6], double theta);

void art_affine_translate(double dst[6], double tx, double ty);

int art_affine_rectilinear(const double src[6]);

Figure 3. Affine Manipulation

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.

       #include <libgnomeui/gnome-canvas.h>

void gnome_canvas_item_i2w_affine(GnomeCanvasItem* item, double affine[6]);

void gnome_canvas_item_i2c_affine(GnomeCanvasItem* item, double affine[6]);

void gnome_canvas_w2c_affine(GnomeCanvas* canvas, double affine[6]);

Figure 4. Canvas Affines

Gtk+/Gnome Application Development
Prev Home Next

  Published under free license. Design by Interspire