PGF offers two different ways of scaling, shifting, and rotating (these operations are generally known as transformations) graphics: You can apply coordinate transformations to all coordinates and you can apply canvas transformations to the canvas on which you draw. (The names “coordinate” and “canvas” transformations are not standard, I introduce them only for the purposes of this manual.)
The difference is the following:
Note that coordinate transformations apply only to coordinates. They do not apply to, say, line width or shadings or text.
In many cases, it is preferable that you use coordinate transformations and not canvas transformations. When canvas transformations are used, PGF looses track of the coordinates of nodes and shapes. Also, canvas transformations often cause undesirable effects like changing text size. For these reasons, PGF makes it easy to setup the coordinate transformation, but a bit harder to change the canvas transformation.
PGF has an internal coordinate transformation matrix. This matrix is applied to coordinates “in certain situations.” This means that the matrix is not always applied to every coordinate “no matter what.” Rather, PGF tries to be reasonably smart at when and how this matrix should be applied. The most prominent examples are the path construction commands, which apply the coordinate transformation matrix to their inputs.
The coordinate transformation matrix consists of four numbers a, b, c, and d, and two dimensions s and t. When the coordinate transformation matrix is applied to a coordinate (x,y) the new coordinate (ax + by + s,cx + dy + t) results. For more details on how transformation matrices work in general, please see, for example, the PDF or PostScript reference or a textbook on computer graphics.
The coordinate transformation matrix is equal to the identity matrix at the beginning. More precisely, a = 1, b = 0, c = 0, d = 1, s = 0pt, and t = 0pt.
The different coordinate transformation commands will modify the matrix by concatenating it with another transformation matrix. This way the effect of applying several transformation commands will accumulate.
The coordinate transformation matrix is local to the current TEX group (unlike the canvas transformation matrix, which is local to the current {pgfscope}). Thus, the effect of adding a coordinate transformation to the coordinate transformation matrix will last only till the end of the current TEX group.
The following commands add a basic coordinate transformation to the current coordinate transformation matrix. For all commands, the transformation is applied in addition to any previous coordinate transformations.
Shifts coordinates by <point>.
|
Shifts coordinates by <dimension> along the x-axis.
|
Like \pgftransformxshift, only for the y-axis.
Scales coordinates by <factor>.
|
Scales coordinates by <factor> in the x-direction.
|
Like \pgftransformxscale, only for the y-axis.
Slants coordinates by <factor> in the x-direction. Here, a factor of 1 means 45o.
|
Slants coordinates by <factor> in the y-direction.
|
Rotates coordinates counterclockwise by <degrees>.
|
Applies the transformation matrix given by a, b, c, and d and the shift <point> to coordinates (in addition to any previous transformations already in force).
|
Shift coordinates to the end of the line going from <start> to <end> with the correct rotation.
|
Shifts coordinates by a specific point on a line at a specific time. The point by which the coordinate is shifted is calculated by calling \pgfpointlineattime, see Section 20.4.2.
In addition to shifting the coordinate, a rotation may also be applied. Whether this is the case depends on whether the TEX if \ifpgfslopedattime is set to true or not.
|
|
There is another TEX if that influences this command. If you set \ifpgfresetnontranslationattime to true, then, between shifting the coordinate and (possibly) rotating/sloping the coordinate, the command \pgftransformresetnontranslations is called. See the description of this command for details.
|
|
Shifts coordinates by a specific point on a curve at a specific time, see Section 20.4.2 once more.
As for the line-at-time transformation command, \ifpgfslopedattime decides whether an additional rotation should be applied.
|
|
The value of \ifpgfresetnontranslationsattime is also taken into account.
Decides whether the “at time” transformation commands also rotate coordinates or not.
Decides whether the “at time” transformation commands should reset the non-translations between shifting and rotating.
The coordinate transformation commands introduced up to now are always applied in addition to any previous transformations. In contrast, the commands presented in the following can be used to change the transformation matrix “absolutely.” Note that this is, in general, dangerous and will often produce unexpected effects. You should use these commands only if you really know what you are doing.
Resets the coordinate transformation matrix to the identity matrix. Thus, once this command is given no transformations are applied till the end of the scope.
|
This command sets the a, b, c, and d part of the coordinate transformation matrix to a = 1, b = 0, c = 0, and d = 1. However, the current shifting of the matrix is not modified.
The effect of this command is that any rotation/scaling/slanting is undone in the current TEX group, but the origin is not “moved back.”
This command is mostly useful directly before a \pgftext command to ensure that the text is not scaled or rotated.
|
Replaces the coordinate transformation matrix by a coordinate transformation matrix that “exactly undoes the original transformation.” For example, if the original transformation was “scale by 2 and then shift right by 1cm” the new one is “shift left by 1cm and then scale by 1/2.”
This command will produce an error if the determinant of the matrix is too small, that is, if the matrix is near-singular.
|
There are two commands for saving and restoring coordinate transformation matrices.
This command will (locally) define <macro> to a representation of the current coordinate transformation matrix. This matrix can later on be reinstalled using \pgfsettransform.
Reinstalls a coordinate transformation matrix that was previously saved using \pgfgettransform.
The canvas transformation matrix is not managed by PGF, but by the output format like PDF or PostScript. All the PGF does is to call appropriate low-level \pgfsys@ commands to change the canvas transformation matrix.
Unlike coordinate transformations, canvas transformations apply to “everything,” including images, text, shadings, line thickness, and so on. The idea is that a canvas transformation really stretches and deforms the canvas after the graphic is finished.
Unlike coordinate transformations, canvas transformations are local to the current {pgfscope}, not to the current TEX group. This is due to the fact that they are managed by the backend driver, not by TEX or PGF.
Unlike the coordinate transformation matrix, it is not possible to “reset” the canvas transformation matrix. The only way to change it is to concatenate it with another canvas transformation matrix or to end the current {pgfscope}.
Unlike coordinate transformations, PGF does not “keep track” of canvas transformations. In particular, it will not be able to correctly save the coordinates of shapes or nodes when a canvas transformation is used.
PGF does not offer a whole set of special commands for modifying the canvas transformation matrix. Instead, different commands allow you to concatenate the canvas transformation matrix with a coordinate transformation matrix (and there are numerous commands for specifying a coordinate transformation, see the previous section).
This command concatenates the canvas transformation matrix with the current coordinate transformation matrix. Afterward, the coordinate transformation matrix is reset.
The effect of this command is to “synchronize” the coordinate transformation matrix and the canvas transformation matrix. All transformations that were previously applied by the coordinate transformations matrix are now applied by the canvas transformation matrix.
|
This command concatenates the canvas transformation matrix with the coordinate transformation specified by <transformation code>.
|
This command creates a local {pgfscope}. Inside this scope, \pgflowlevel is first called with the argument <transformation code>, then the <code> is inserted.
|
This environment first surrounds the <environment contents> by a {pgfscope}. Then it calls \pgflowlevel with the argument <transformation code>.
|