Penultimate draft
[ipdf/sam.git] / chapters / Background / CoordinateSystems.tex
1 The literature discussed in Chapter \ref{Background} is primarily concerned with the rendering process for graphical primitives, namely outlines defined by B\'{e}zier curves. We have seen that basic vector primitives composed of B{\'e}ziers may be rendered using only integer operations, once the starting and ending positions are rounded to the nearest pixel.
2
3 However, a complete document will contain many such primitives which in general cannot all be shown on a display at once. A ``View'' rectangle can be defined to represent the size of the display relative to the document. To interact with the document a user can change this view through scaling or translating with the mouse.
4
5 Primitives which are contained within the view rectangle will be visible on the display. This involves the transformation from coordinates within the document to relative coordinates within the view rectangle as illustrated in Figure \ref{view_transformation_minimal.pdf}. A point $(X,Y)$ in the document will transform to a point $(S_X,S_Y)$ in the display by:
6 \begin{align}
7         S_X = \frac{X - V_x}{V_w} &\quad\quad S_Y = \frac{Y - V_y}{V_h}\label{view-transformation}
8 \end{align}
9 Where $(V_x,V_y)$ are the coordinates of the top left corner and $(V_w,V_h)$ are the dimensions of the view rectangle.
10
11
12 The transformation may also be written as a 3x3 matrix $\matx{V}$ if we introduce a third coordinate $z = 1$
13 \begin{align}
14         \left( \begin{array}{c} S_X \\ S_Y \\ 1 \end{array}\right) &= 
15         \left( \begin{array}{ccc} 
16                 \frac{1}{V_w} & 0 & \frac{V_x}{V_w} \\
17                 0 & \frac{1}{V_h} & \frac{V_y}{V_h} \\
18                 0 & 0 & 1 
19         \end{array}\right) 
20         \left( \begin{array}{c} X \\ Y \\ 1 \end{array}\right)\label{view-transformation-matrix}
21 \end{align}
22
23 This transformation can be used not just for the view, but in any mapping of points from one coordinate system to another one which is defined by some bounds rectangle. In particular, our implementations of B\'{e}zier rendering use this transformation to re-express control points relative to the bounding rectangle (whilst in the SVG standard, control points are specified relative to the document).
24
25 \begin{figure}[H]
26         \centering
27         \includegraphics[width=0.7\textwidth]{figures/view_transformation_minimal.pdf}
28         \caption{Illustration of view transformation \eqref{view-transformation}}\label{view_transformation_minimal.pdf}
29 \end{figure}
30
31 \subsection{View Transformations}
32
33 Moving the mouse (or on a touch screen, swiping the screen) by a distance $(\Delta x, \Delta y)$ relative to the size of the view should translate it by the same amount:
34 \begin{align}
35         V_x \to V_x + \Delta x &\quad \quad V_y \to V_y + \Delta y
36 \end{align}
37
38 The document can be scaled by a factor of $s$ about a point $(x_0,y_0)$ specified relative to the view (such as the position of the mouse cursor):
39 \begin{align}
40         V_x \to V_x + x_0 V_w(1 - s) &\quad \quad V_y \to V_y + y_0 V_h(1 - s) \\
41         V_w \to s V_w &\quad \quad V_h \to s V_h
42 \end{align}
43
44 The effect of this transformation is that, measured relative to the view rectangle, the distance of primitives with coordinates $(x, y)$ to the point $(x_0, y_0)$ will decrease by a factor of $s$. For $s < 1$ the operation is ``zooming out'' and for $s > 1$, ``zooming in''.
45
46 As we will see in Chapter \ref{Results and Discussion}, the application of the transformations discussed in this section can cause issues with the rendering of vector graphics even when the primitives are specified with coordinates compliant with the SVG standard.
47
48
49 %TODO List
50 % Mention that these transformations affect precision more than eg: drawing a line
51 % Discuss floating point errors that could occur?
52 % Convert operations to Matrix form, more standard
53 % Cite some UI paper or something

UCC git Repository :: git.ucc.asn.au