3.3.4 Mapping functions

The following are the “mapping functions” in (plotutils plot). When invoked on a <plotter>, they affect the affine transformation it employs to map the user coordinate system to the device coordinate system. That is, they affect the transformation matrix attribute of objects subsequently drawn on the graphics display.

The names of these functions resemble those of the corresponding functions in the Postscript language. For information on how to use them to draw graphics efficiently, consult any good book on Postscript programming, or the Postscript Language Reference Manual.

Each of these functions, if called, terminates and draws the path under construction (if any), as if endpath! had been called.

In the current Guile binding, each of these functions takes a <plotter> as its first argument.

Procedure: setmatrix! plotter m0 m1 m2 m3 tx ty

Use the Postscript-style transformation matrix [m0 m1 m2 m3 tx ty] as the transformation matrix from user space to NDC (normalized device coordinate) space. This matrix determines the transformation matrix from user space to unnormalized device space, i.e., sets the transformation matrix attribute that will be used when subsequently drawing objects on the graphics display.

In NDC space, the graphics display (i.e., viewport) has corners (0,0), (1,0), (1,1), and (0,1). For information on the size of the graphics display in physical units, see Page Sizes and Viewport Sizes.

The default transformation matrix from user space to NDC space is [1 0 0 1 0 0], which means that by default, user coordinates are the same as NDC coordinates. This transformation matrix is also altered by space!, space2!, and by the following functions.

Procedure: concat m0 m1 m2 m3 tx ty

Modify the transformation matrix from user space to NDC space by pre-multiplying it by the matrix [m0 m1 m2 m3 tx ty]. Equivalently, apply the linear transformation defined by the two-by-two matrix [m0 m1 m2 m3] to the user coordinate system, and then translate by tx units in the x direction and ty units in the y direction.

concat! is a wrapper around the more fundamental fsetmatrix function. The following three functions (frotate, fscale, translate!) are convenience functions that are special cases of concat!.

Procedure: rotate! plotter theta

Modify the transformation matrix from user space to NDC space by pre-multiplying it by the matrix [cos(theta) sin(theta) −sin(theta) cos(theta) 0 0]. Equivalently, rotate the user coordinate system axes about their origin by theta degrees counterclockwise, with respect to their former orientation. The position of the user coordinate origin and the size of the x and y units remain unchanged.

Procedure: scale! plotter sx sy

Modify the transformation matrix from user space to NDC space by pre-multiplying it by the matrix [sx 0 0 sy 0 0]. Equivalently, make the x and y units in the user coordinate system be the size of sx and sy units in the former user coordinate system. The position of the user coordinate origin and the orientation of the coordinate axes are unchanged.

Procedure: translate! plotter tx ty

Modify the transformation matrix from user space to NDC space by pre-multiplying it by the matrix [0 0 0 0 tx ty]. Equivalently, move the origin of the user coordinate system by tx units in the x direction and ty units in the y direction, relative to the former user coordinate system. The size of the x and y units and the orientation of the coordinate axes are unchanged.