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

2D Affine Transformation (CGAL_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

CGAL_Aff_transformation_2<R> t ( const CGAL_Translation,
CGAL_Vector_2<R> v);
introduces a translation by a vector v.

CGAL_Aff_transformation_2<R> t ( const CGAL_Rotation,
CGAL_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.

CGAL_Aff_transformation_2<R> t ( const CGAL_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 .

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

CGAL_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 . 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.

CGAL_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 , i.e. there is no translational part.

Operations

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

CGAL_Class_2<R> transform(CGAL_Aff_transformation_2<R> t) .

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

CGAL_Point_2<R> t.transform ( CGAL_Point_2<R> p)
CGAL_Vector_2<R> t.transform ( CGAL_Vector_2<R> p)
CGAL_Direction_2<R>
t.transform ( CGAL_Direction_2<R> p)
CGAL_Line_2<R> t.transform ( CGAL_Line_2<R> p)

CGAL provides function operators for these member functions:

CGAL_Point_2<R> t ( CGAL_Point_2<R> p)
CGAL_Vector_2<R> t ( CGAL_Vector_2<R> p)
CGAL_Direction_2<R>
t ( CGAL_Direction_2<R> p)
CGAL_Line_2<R> t ( CGAL_Line_2<R> p)

Miscellaneous

CGAL_Aff_transformation_2<R>
t * s composes two affine transformations.
CGAL_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 CGAL_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 CGAL_Cartesian<double> RepClass;
  typedef CGAL_Aff_transformation_2<RepClass> Transformation;
  typedef CGAL_Point_2<RepClass> Point;
  typedef CGAL_Vector_2<RepClass> Vector;
  typedef CGAL_Direction_2<RepClass> Direction;

  Transformation rotate(CGAL_ROTATION, sin(pi), cos(pi));
  Transformation rational_rotate(CGAL_ROTATION,Direction(1,1), 1, 100);
  Transformation translate(CGAL_TRANSLATION, Vector(-2, 0));
  Transformation scale(CGAL_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));


Return to chapter: 2D Transformations
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Wed, January 20, 1999.