1 \chapter{Module trafo: linear transformations
}
5 With the
\verb|trafo| modulo
\PyX\ provides linear transformations, which can then
6 be applied to canvases, B\'ezier paths and other objects. It consists
7 of the main class
\verb|trafo| representing a general linear
8 transformation and subclasses thereof, which give special operations
9 like translation, rotation, scaling, and mirroring.
13 The
\verb|trafo| class represents a general
14 transformation, which is defined for a vector $
\vec{x
}$ as
16 \vec{x
}' =
\mathsf{A
}\,
\vec{x
} +
\vec{b
}\ ,
18 where $
\mathsf{A
}$ is the transformation matrix and $
\vec{b
}$ the
19 translation vector. The transformation matrix must not be singular,
20 \textit{i.e.
} we require $
\det \mathsf{A
} \ne 0$.
24 Multiple
\verb|trafo| instances can be multiplied, corresponding to a
25 consecutive application of the respective transformation. Note that
26 \verb|trafo1*trafo2| means that first
\verb|trafo2| gets applied and
27 then
\verb|trafo1|,
\textit{i.e.
} the new transformation is given in
28 obvious notation by $
\mathsf{A
} =
\mathsf{A
}_1
\mathsf{A
}_2$ and
29 $
\vec{b
} =
\mathsf{A
}_1
\vec{b
}_2 +
\vec{b
}_1$. Use the
\verb|trafo|
30 methods described below, if you prefer thinking the other way round.
31 The inverse of a transformation can be obtained via the
\verb|trafo|
32 method
\verb|inverse()|, defined by the inverse $
\mathsf{A
}^
{-
1}$ of
33 the transformation matrix and the transformation vector
34 $-
\mathsf{A
}^
{-
1}\vec{b
}$.
36 The methods of the
\verb|trafo| class are summarized in the following
40 \begin{tabularx
}{\linewidth}{>
{\hsize=
.8\hsize}X>
{\raggedright\arraybackslash\hsize=
1.2\hsize}X
}
41 \texttt{trafo
} method & function \\
43 \texttt{\_\_init\_\_(matrix=((
1,
0),(
0,
1)),
\newline
44 \phantom{\_\_init\_\_(
}vector=(
0,
0)):
} & create new
\texttt{trafo
}
45 instance with transformation
\texttt{matrix
} and
\texttt{vector
}.
47 \texttt{apply(x, y)
} & apply
\texttt{trafo
} to point vector
48 $(
\mathtt{x
},
\mathtt{y
})$.\\
49 \texttt{inverse()
} & returns inverse transformation of
51 \texttt{mirror(angle)
} & returns
\texttt{trafo
} followed by mirroring
52 at line through $(
0,
0)$ with direction
\texttt{angle
} in degrees.\\
53 \texttt{rotate(angle,
\newline\phantom{rotate(
}x=None, y=None)
} &
54 returns
\texttt{trafo
} followed by rotation by
\texttt{angle
} degrees
55 around point $(
\mathtt{x
},
56 \mathtt{y
})$, or $(
0,
0)$, if not given.\\
57 \texttt{scale(sx, sy=None,
\newline\phantom{scale(
}x=None, y=None)
} &
58 returns
\texttt{trafo
} followed by
59 scaling with scaling factor
\texttt{sx
} in $x$-direction,
\texttt{sy
} in
60 $y$-direction ($
\mathtt{sy
}=
\mathtt{sx
}$, if not given) with scaling
61 center $(
\mathtt{x
},
\mathtt{y
})$, or $(
0,
0)$, if not given.\\
62 \texttt{translate(x, y)
} & returns
\texttt{trafo
} followed by
63 translation by vector $(
\mathtt{x
},
\mathtt{y
})$.\\
69 \section{Subclasses of trafo
}
71 The
\verb|trafo| module provides provides a number of subclasses of
72 the
\verb|trafo| class, each of which corresponds to one
\verb|trafo|
73 method. They are listed in the following table:
76 \begin{tabularx
}{\linewidth}{>
{\hsize=
.7\hsize}X>
{\raggedright\arraybackslash\hsize=
1.3\hsize}X
}
77 \texttt{trafo
} subclass & function \\
79 \texttt{mirroring(angle)
} & mirroring at line through $(
0,
0)$
80 with direction
\texttt{angle
} in degrees.\\
81 \texttt{rotation(angle,
\newline\phantom{rotation(
}x=None, y=None)
} &
82 rotation by
\texttt{angle
} degrees around point $(
\mathtt{x
},
83 \mathtt{y
})$, or $(
0,
0)$, if not given.\\
84 \texttt{scaling(sx, sy=None,
\newline\phantom{scaling(
}x=None, y=None)
} &
85 scaling with scaling factor
\texttt{sx
} in $x$-direction,
86 \texttt{sy
} in $y$-direction ($
\mathtt{sy
}=
\mathtt{sx
}$, if not
88 center $(
\mathtt{x
},
\mathtt{y
})$, or $(
0,
0)$, if not given.\\
89 \texttt{translation(x, y)
} &
90 translation by vector $(
\mathtt{x
},
\mathtt{y
})$.\\
101 %%% TeX-master: "manual.tex"