CGAL 6.0 - 2D and 3D Linear Geometry Kernel
Loading...
Searching...
No Matches
CGAL::Aff_transformation_2< Kernel > Class Template Reference

#include <CGAL/Aff_transformation_2.h>

## Definition

template<typename Kernel>
class CGAL::Aff_transformation_2< Kernel >

The class Aff_transformation_2 represents two-dimensional affine transformations.

The general form of an affine transformation is based on a homogeneous representation of points. Thereby all transformations can be realized by matrix multiplications.

Multiplying the transformation matrix by a scalar does not change the represented transformation. Therefore, any transformation represented by a matrix with rational entries can be represented by a transformation matrix with integer entries as well. (Multiply the matrix with the common denominator of the rational entries.) Hence, it is sufficient to use the number type Kernel::RT to represent the entries of the transformation matrix.

CGAL offers several specialized affine transformations. Different constructors are provided to create them. They are parameterized with a symbolic name to denote the transformation type, followed by additional parameters. The symbolic name tags solve ambiguities in the function overloading and they make the code more readable, i.e., what type of transformation is created.

Since two-dimensional points have three homogeneous coordinates, we have a $$3\times 3$$ matrix $${(m_{ij})}_{i,\,j=0\ldots 2}$$.

If the homogeneous representations are normalized (the homogenizing coordinate is 1), then the upper left $$2\times 2$$ matrix realizes linear transformations. In the matrix form of a translation, the translation vector $$(v_0,\,v_1,\,1)$$ appears in the last column of the matrix. The entries $$m_{20}$$ and $$m_{21}$$ are always zero and therefore do not appear in the constructors.

Is model of
Hashable if Kernel is a cartesian kernel and if Kernel::FT is Hashable
See also
Identity_transformation
Rotation
Scaling
Translation
Reflection
CGAL::rational_rotation_approximation()

Example

typedef CGAL::Aff_transformation_2<K> Transformation;
typedef CGAL::Point_2<K> Point;
typedef CGAL::Direction_2<K> 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 class Aff_transformation_2 represents two-dimensional affine transformations.
Definition: Aff_transformation_2.h:87
An object d of the class Direction_2 is a vector in the two-dimensional vector space where we forget...
Definition: Direction_2.h:21
An object p of the class Point_2 is a point in the two-dimensional Euclidean plane .
Definition: Point_2.h:37
An object v of the class Vector_2 is a vector in the two-dimensional vector space .
Definition: Vector_2.h:19
A model for a Kernel using Cartesian coordinates to represent the geometric objects.
Definition: Simple_cartesian.h:31

The same would have been achieved with

Transformation transform = scale * (translate * rotate);
p = transform(Point(1.0, 1.0));
Point_2< Kernel > transform(const Point_2< Kernel > &p) const
See also
CGAL::Aff_transformation_3<Kernel>
CGAL::Identity_transformation
CGAL::Reflection
CGAL::Rotation
CGAL::Scaling
CGAL::Translation

## Creation

Aff_transformation_2 (const Identity_transformation &)
introduces an identity transformation.

Aff_transformation_2 (const Translation, const Vector_2< Kernel > &v)
introduces a translation by a vector v.

Aff_transformation_2 (const Rotation, const Direction_2< Kernel > &d, const Kernel::RT &num, const Kernel::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.

Aff_transformation_2 (const Rotation, const Kernel::RT &sine_rho, const Kernel::RT &cosine_rho, const Kernel::RT &hw=RT(1))
introduces a rotation by the angle rho.

Aff_transformation_2 (const Scaling, const Kernel::RT &s, const Kernel::RT &hw=RT(1))
introduces a scaling by a scale factor $$s/hw$$.

Aff_transformation_2 (const Reflection, const Line_2< Kernel > &l)
introduces a reflection by a line l.

Aff_transformation_2 (const Kernel::RT &m00, const Kernel::RT &m01, const Kernel::RT &m02, const Kernel::RT &m10, const Kernel::RT &m11, const Kernel::RT &m12, const Kernel::RT &hw=RT(1))
introduces a general affine transformation in the $$3 \times 3$$ matrix form $$\small \mbox{\( \left(\begin{array}{ccc} m_{00} & m_{01} & m_{02}\\ m_{10} & m_{11} & m_{12}\\ 0 & 0 & hw \end{array}\right)$$} \).

Aff_transformation_2 (const Kernel::RT &m00, const Kernel::RT &m01, const Kernel::RT &m10, const Kernel::RT &m11, const Kernel::RT &hw=RT(1))
introduces a general linear transformation $$\small \mbox{\(\left(\begin{array}{ccc} m_{00} & m_{01} & 0\\ m_{10} & m_{11} & 0\\ 0 & 0 & hw \end{array}\right)$$}\) 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<Kernel> representing a geometric object has a member function:

The transformation classes provide a member function transform() for points, vectors, directions, and lines. The same functionality is also available through operator() overloads.

Point_2< Kerneltransform (const Point_2< Kernel > &p) const

Vector_2< Kerneltransform (const Vector_2< Kernel > &p) const

Direction_2< Kerneltransform (const Direction_2< Kernel > &p) const

Line_2< Kerneltransform (const Line_2< Kernel > &p) const

Point_2< Kerneloperator() (const Point_2< Kernel > &p) const

Vector_2< Kerneloperator() (const Vector_2< Kernel > &p) const

Direction_2< Kerneloperator() (const Direction_2< Kernel > &p) const

Line_2< Kerneloperator() (const Line_2< Kernel > &p) const

## Miscellaneous

Aff_transformation_2< Kerneloperator* (const Aff_transformation_2< Kernel > &s) const
composes two affine transformations.

Aff_transformation_2< Kernelinverse () const
gives the inverse transformation.

bool operator== (const Aff_transformation_2< Kernel > &s) const
compares two affine transformations.

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

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

bool is_scaling () const
returns true, if the object was constructed using the tag CGAL::Scaling, or is the result of the composition of only such scaling transformation objects.

bool is_translation () const
returns true, if the object was constructed using the tag CGAL::Translation, or is the result of the composition of only such translation transformation objects.

bool is_rotation () const
returns true, if the object was constructed using the tag CGAL::Rotation, or is the result of the composition of only such rotation transformation objects.

bool is_reflection () const
returns true, if the object was constructed using the tag CGAL::Reflection, or is the result of the composition of only such reflection transformation objects.

## Matrix Entry Access

Kernel::FT cartesian (int i, int j) const

Kernel::FT m (int i, int j) const
returns entry $$m_{ij}$$ in a matrix representation in which $$m_{22}$$ is 1.

Kernel::RT homogeneous (int i, int j) const

Kernel::RT hm (int i, int j) const
returns entry $$m_{ij}$$ in some fixed matrix representation.

## ◆ Aff_transformation_2() [1/3]

template<typename Kernel >
 CGAL::Aff_transformation_2< Kernel >::Aff_transformation_2 ( const Rotation, const Direction_2< Kernel > & d, const Kernel::RT & num, const Kernel::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 and d != 0.

## ◆ Aff_transformation_2() [2/3]

template<typename Kernel >
 CGAL::Aff_transformation_2< Kernel >::Aff_transformation_2 ( const Rotation, const Kernel::RT & sine_rho, const Kernel::RT & cosine_rho, const Kernel::RT & hw = RT(1) )

introduces a rotation by the angle rho.

Precondition
sine_rho2 + cosine_rho2 == hw2.

## ◆ Aff_transformation_2() [3/3]

template<typename Kernel >
 CGAL::Aff_transformation_2< Kernel >::Aff_transformation_2 ( const Kernel::RT & m00, const Kernel::RT & m01, const Kernel::RT & m02, const Kernel::RT & m10, const Kernel::RT & m11, const Kernel::RT & m12, const Kernel::RT & hw = RT(1) )

introduces a general affine transformation in the $$3 \times 3$$ matrix form $$\small \mbox{\( \left(\begin{array}{ccc} m_{00} & m_{01} & m_{02}\\ m_{10} & m_{11} & m_{12}\\ 0 & 0 & hw \end{array}\right)$$} \).

The sub-matrix $$1\over hw$$ $$\small \mbox{\( \left(\begin{array}{cc} m_{00} & m_{01}\\ m_{10} & m_{11} \end{array}\right)$$ } \) contains the scaling and rotation information, the vector $$\small \left( \begin{array}{c} m_{02}\\ m_{12} \end{array} \right)$$ contains the translational part of the transformation.