Module trafo: Linear transformations¶
With the trafo module PyX supports linear transformations, which can then
be applied to canvases, Bézier paths and other objects. It consists of the main
class trafo representing a general linear transformation and subclasses
thereof, which provide special operations like translation, rotation, scaling,
and mirroring.
Class trafo¶
The trafo class represents a general linear transformation, which is defined
for a vector \(\vec{x}\) as
where \(\mathsf{A}\) is the transformation matrix and \(\vec{b}\) the translation vector. The transformation matrix must not be singular, i.e. we require \(\det \mathsf{A} \ne 0\).
Multiple trafo instances can be multiplied, corresponding to a consecutive
application of the respective transformation. Note that trafo1*trafo2 means
that trafo1 is applied after trafo2, i.e. the new transformation is
given by \(\mathsf{A} = \mathsf{A}_1 \mathsf{A}_2\) and \(\vec{b} =
\mathsf{A}_1 \vec{b}_2 + \vec{b}_1\). Use the trafo methods described below,
if you prefer thinking the other way round. The inverse of a transformation can
be obtained via the trafo method inverse(), defined by the inverse
\(\mathsf{A}^{-1}\) of the transformation matrix and the translation vector
\(-\mathsf{A}^{-1}\vec{b}\).
-
class
trafo.trafo(matrix=1, 0, 0, 1, vector=0, 0)¶ create new
trafoinstance with transformationmatrixandvector
-
trafo.apply(x, y)¶ apply
trafoto point vector \((\mathtt{x}, \mathtt{y})\).
-
trafo.inverse()¶ returns inverse transformation of
trafo.
-
trafo.mirrored(angle)¶ returns
trafofollowed by mirroring at line through \((0,0)\) with directionanglein degrees.
-
trafo.rotated(angle, x=None, y=None)¶ returns
trafofollowed by rotation byangledegrees around point \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
trafo.scaled(sx, sy=None, x=None, y=None)¶ returns
trafofollowed by scaling with scaling factorsxin \(x\)-direction,syin \(y\)-direction (\(\mathtt{sy}=\mathtt{sx}\), if not given) with scaling center \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
trafo.slanted(a, angle=0, x=None, y=None)¶ returns
trafofollowed by slant byanglearound point \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
trafo.translated(x, y)¶ returns
trafofollowed by translation by vector \((\mathtt{x}, \mathtt{y})\).
Subclasses of trafo¶
The trafo module provides a number of subclasses of the trafo class,
each of which corresponds to one trafo method.
-
class
trafo.mirror(angle)¶ mirroring at line through \((0,0)\) with direction
anglein degrees.
-
class
trafo.rotate(angle, x=None, y=None)¶ rotation by
angledegrees around point \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
class
trafo.scale(sx, sy=None, x=None, y=None)¶ scaling with scaling factor
sxin \(x\)-direction,syin \(y\)-direction (\(\mathtt{sy}=\mathtt{sx}\), if not given) with scaling center \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
class
trafo.slant(a, angle=0, x=None, y=None)¶ slant by
anglearound point \((\mathtt{x}, \mathtt{y})\), or \((0,0)\), if not given.
-
class
trafo.translate(x, y)¶ translation by vector \((\mathtt{x}, \mathtt{y})\).