Coordinate systems for windows generally have the origin (0,0) positioned at the upper left corner of the window with X positive to the right and Y positive downwards. This is the "window coordinates" system. Generalized coordinates are implemented using scaling, rotation and translation operations such that any Cartesian coordinates can be used within a window. The Graphics Ports system uses a transform object to achieve this.

An (x, y) coordinate pair can be transformed to another coordinate system by scaling, rotation and translation. The first two can be implemented using 2 x 2 matrices to hold the coefficients:

If the point `
P`
is `
(a, b)`
and it is transformed to the point `
Q (a', b')`

Translation can be included in this if the points `
P`
and `
Q`
are regarded as 3-vectors instead of 2-vectors, with the 3rd element being unity:

The coefficients `
u`
and `
v`
specify the translation.

So, the six elements (`
p`
, `
q`
, `
r`
, `
s`
, `
u`
, and `
v`
) of the 3 x 3 matrix contain all the transformation information. These elements are stored in a list (of type transform) in the graphics-state slot `
transform`
.

Transforms can be combined by matrix multiplication to effect successions of translation, scaling and rotation operations.

Functions are provided in Graphics Ports which apply translation, scaling and rotation to a transform, combine transforms by pre- or post-multiplication, invert a transform, perform some operations while ignoring an established transform, and so on. The macros with-graphics-rotation, with-graphics-scale and with-graphics-translation pre-multiply a supplied transform while a body of code is executed.

Drawing functions such as draw-line and draw-ellipse modify pixels, but you cannot assume that they have exactly the same effect on all platforms. Some platforms might put pixels below and to the right of integer coordinates`
(x y)`
while others may center the pixel at `
(x y)`
.

This applies to all the drawing functions which are documented in GRAPHICS-PORTS Reference Entries - see the entries for functions with names beginning `draw-`

.

*CAPI User Guide and Reference Manual (Macintosh version) - 3 Aug 2017*