Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Affine transformations

Transformations of the plane such as rotation and scaling. More...

Classes

class  Geom::Affine
 3x3 matrix representing an affine transformation. More...
 
class  Geom::Translate
 Translation by a vector. More...
 
class  Geom::Scale
 Scaling from the origin. More...
 
class  Geom::Rotate
 Rotation around the origin. More...
 
class  Geom::ShearBase< S >
 Common base for shearing transforms. More...
 
class  Geom::HShear
 Horizontal shearing. More...
 
class  Geom::VShear
 Vertical shearing. More...
 
class  Geom::Zoom
 Combination of a translation and uniform scale. More...
 

Functions

template<typename T >
Geom::pow (T const &t, int n)
 Integer exponentiation for transforms.
 
Affine Geom::reflection (Point const &vector, Point const &origin)
 Reflects objects about line.
 

Detailed Description

Transformations of the plane such as rotation and scaling.

Each transformation class represent a set of affine transforms that is closed under multiplication. Those are translation, scaling, rotation, horizontal shearing and vertical shearing. Any affine transform can be obtained by combining those basic operations.

Each of the transforms can be applied to points and matrices (using multiplication). Each can also be converted into a matrix (which can represent any composition of transforms generically). All (except translation) use the origin (0,0) as the invariant point (e.g. one that stays in the same place after applying the transform to the plane). To obtain transforms with different invariant points, combine them with translation to and back from the origin. For example, to get a 60 degree rotation around the point p:

Affine rot_around_p = Translate(-p) * Rotate::from_degrees(60) * Translate(p);

Multiplication of transforms is associative: the result of an expression involving points and matrices is the same regardless of the order of evaluating multiplications.

If you need to transform a complicated object by A, then B, and then C, you should first compute the total transform and apply it to the object in one go. This way instead of performing 3 expensive operations, you will only do two very fast matrix multiplications and one complex transformation. Here is an example:

transformed_path = long_path * A * B * C; // wrong! long_path will be transformed 3 times.
transformed_path = long_path * (A * B * C); // good! long_path will be transformed only once.
Affine total = A * B * C; // you can store the transform to apply it to several objects.
transformed_path = long_path * total; // good!

Ordering note: if you compose transformations via multiplication, they are applied from left to right. If you write ptrans = p * A * B * C * D;, then it means that ptrans is obtained from p by first transforming it by A, then by B, then by C, and finally by D. This is a consequence of interpreting points as row vectors, instead of the more common column vector interpretation; 2Geom's choice leads to more intuitive notation.

Function Documentation

◆ pow()

template<typename T >
T Geom::pow ( T const &  t,
int  n 
)

Integer exponentiation for transforms.

Negative exponents will yield the corresponding power of the inverse. This function can also be applied to matrices.

Parameters
tAffine or transform to exponantiate
nExponent
Returns
\(A^n\) if n is positive, \((A^{-1})^n\) if negative, identity if zero.

Definition at line 98 of file transforms.h.

References Geom::pow(), and result.

Referenced by Geom::TransformConcept< T >::constraints(), Inkscape::LivePathEffect::LPELattice::doEffect_pwd2(), Inkscape::LivePathEffect::LPELattice2::doEffect_pwd2(), exp_rescale(), lambertW(), Geom::pow(), pow_sample_based(), and trial_eval().

◆ reflection()

Affine Geom::reflection ( Point const &  vector,
Point const &  origin 
)

Reflects objects about line.

The line, defined by a vector along the line and a point on it, acts as a mirror.

See also
Line::reflection()

Definition at line 148 of file transforms.cpp.

References origin, Geom::unit_vector(), Geom::X, and Geom::Y.

Referenced by Inkscape::LivePathEffect::LPEMirrorSymmetry::doAfterEffect(), Inkscape::LivePathEffect::LPEMirrorSymmetry::doEffect_path(), and Inkscape::LivePathEffect::path_from_piecewise_fix_cusps().