Navigation: Up, Table of Contents, Bibliography, Index, Title Page

2D Affine Transformation (Aff_transformation_2)

Definition

Since two-dimensional points have three homogeneous coordinates we have a 3 × 3 matrix (mij). Following C-style, the indices start at zero.

If the homogeneous representations are normalized such that the homogenizing coordinate is 1, then the upper left 2 × 2 matrix realizes linear transformations and in the matrix form of a translation, the translation vector (v0, v1, 1) appears in the last column of the matrix. In the normalized case, entry hw is always 1. Entries m20 and m21 are always zero and therefore do not appear in the constructors.

#include <CGAL/Aff_transformation_2.h>

Creation

Aff_transformation_2<R> t ( const Translation, Vector_2<R> v);
introduces a translation by a vector v.


Aff_transformation_2<R> t ( const Rotation,
Direction_2<R> d,
R::RT num,
R::RT den = RT(1));
approximates the rotation over the angle indicated by direction d, such that the differences between the sines and cosines of the rotation given by d and the approximating rotation are at most num/den each.
Precondition: num/den>0.


Aff_transformation_2<R> t ( const Rotation,
R::RT sine_rho,
R::RT cosine_rho,
R::RT hw = RT(1));
introduces a rotation by the angle rho.
Precondition: sine_rho2 + cosine_rho2 == hw2.


Aff_transformation_2<R> t ( const Scaling, R::RT s, R::RT hw = RT(1));
introduces a scaling by a scale factor s/hw.


Aff_transformation_2<R> t ( R::RT m00,
R::RT m01,
R::RT m02,
R::RT m10,
R::RT m11,
R::RT m12,
R::RT hw = RT(1));
introduces a general affine transformation in the 3x3 matrix form (
m00 m01 m02
m10 m11 m12
0 0 hw
)
. The sub-matrix 1/hw((m00, m10)t, (m01, m11)t) contains the scaling and rotation information, the vector 1/hw(m02, m12)t contains the translational part of the transformation.


Aff_transformation_2<R> t ( R::RT m00,
R::RT m01,
R::RT m10,
R::RT m11,
R::RT hw = RT(1));
introduces a general linear transformation (
m00 m01 0
m10 m11 0
0 0 hw
)
, i.e. there is no translational part.

Operations

The main thing to do with transformations is to apply them on geometric objects. Each class Class_2<R> representing a geometric object has a member function:

Class_2<R> transform(Aff_transformation_2<R> t).

The transformation classes provide a member function transform() for points, vectors, directions, and lines:

Point_2<R> t.transform ( Point_2<R> p)
Vector_2<R> t.transform ( Vector_2<R> p)
Direction_2<R> t.transform ( Direction_2<R> p)
Line_2<R> t.transform ( Line_2<R> p)

CGAL provides function operators for these member functions:

Point_2<R> t ( Point_2<R> p)
Vector_2<R> t ( Vector_2<R> p)
Direction_2<R> t ( Direction_2<R> p)
Line_2<R> t ( Line_2<R> p)

Miscellaneous

Aff_transformation_2<R>
t * s composes two affine transformations.

Aff_transformation_2<R>
t.inverse () gives the inverse transformation.

bool t.is_even () returns true, if the transformation is not reflecting, i.e. the determinant of the involved linear transformation is non-negative.

bool t.is_odd () returns true, if the transformation is reflecting.

The matrix entries of a matrix representation of a Aff_transformation_2<R> can be accessed trough the following member functions:

FT t.cartesian ( int i, int j)

FT t.m ( int i, int j)
returns entry mij in a matrix representation in which m22 is 1.

RT t.homogeneous ( int i, int j)

RT t.hm ( int i, int j)
returns entry mij in some fixed matrix representation.

For affine transformations no I/O operators are defined.

Implementation

Depending on the constructor we have different internal representations. This approach uses less memory and the transformation can be applied faster.

Affine transformations offer no transform() member function for complex objects because they are defined in terms of points vectors and directions. As the internal representation of a complex object is private the transformation code should go there.

Example

  typedef Cartesian<double> RepClass;
  typedef Aff_transformation_2<RepClass> Transformation;
  typedef Point_2<RepClass> Point;
  typedef Vector_2<RepClass> Vector;
  typedef Direction_2<RepClass> Direction;

  Transformation rotate(ROTATION, sin(pi), cos(pi));
  Transformation rational_rotate(ROTATION,Direction(1,1), 1, 100);
  Transformation translate(TRANSLATION, Vector(-2, 0));
  Transformation scale(SCALING, 3);

  Point q(0, 1);
  q = rational_rotate(q); 

  Point p(1, 1);

  p = rotate(p); 

  p = translate(p); 

  p = scale(p);

The same would have been achieved with


  Transformation transform = scale * (translate * rotate);
  p = transform(Point(1.0, 1.0));

Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The GALIA project. Jan 18, 2000.