Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Affine Transformations


Affine Transformations

What is an Affine Transformation?

Transformations change the positions of points in the plane. A set of points, for example a rectangle, may acquire a different shape when transformed.

The transformations that move lines into lines, while preserving their intersection properties, are special and interesting, because they will move all polylines into polylines and all polygons into polygons. These are called affine transformations.

An affine transformation of the plane is specified by a 3x3 matrix T with T2,0=T2,1=0 and T2,2!=0.It maps the point p with the homogeneous coordinate vector (px,py,pw) to the point T*p.

If T1 and T2 are transformations then T2(T1) is the transformation obtained by first applying T1 and then applying T2.

Translations, rotations, and reflections are special cases of affine transformations.

Practical Applications

Affine transformations play an important role, for example, in geographical information systems (GIS), where it is sometimes necessary to change the units of measurement, rotate a map, change the origin of a coordinate system, or remove a uniform distortion.

Example

The following program shows how the LEDA data type rat_transform can be used. First it defines an integer_matrix IM and uses IM to define a (general) affine transformation. To show the effect of this transformation, it outputs ten points on the line y=x+1 and the resulting points (on the line y=2x+1. Then a rotation around the origin by 90 degrees is defined and the effect is shown again on y=x+1. The resulting line is y=-x-1.

#include <LEDA/geo/rat_transform.h>
#include <LEDA/numbers/integer_matrix.h>

using namespace leda;

int main()
{ 
  integer_matrix IM(3,3);
  IM(0,0)=1; IM(0,1)=0; IM(0,2)=1;
  IM(1,0)=0; IM(1,1)=2; IM(1,2)=1;
  IM(2,0)=0; IM(2,1)=0; IM(2,2)=1;

  rat_transform T(IM);
  //maps (0,1) to (1,3), (1,2) to (2,5), (2,3) to (3,7), ...

  std::cout << "General Transformation:" << std::endl;
  int i;
  for (i=0;i<10;i++) {
    rat_point p(i,i+1);
    rat_point q=T(p);

    std::cout << p.to_point() << " " << q.to_point() << std::endl;
  }

  TRANSFORM TROT=rotation90(point(0,0));

  std::cout << std::endl << "Rotation about origin by 90 degrees:" << std::endl;
  for (i=0;i<10;i++) {
    rat_point p(i,i+1);
    rat_point q=TROT(p);

    std::cout << p.to_point() << " " << q.to_point() << std::endl;
  }

  return 0;
}	

See also:

Double Valued Vectors and Matrices

Data Types for 2D Geometry

Cartesian and Homogeneous Coordinates

Writing Kernel Independent Code


Geometry

Advanced Data types for 2-D geometry

Data Types for 3-D Geometry

Geometry Algorithms

GeoWin


Manual Entries:

Manual Page TRANSFROM




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH