a8e90efd8463e787b5c1185e99a39a808fa6c495
[ctsim.git] / doc / ctsim-appendix.tex
1 \appendix
2
3 \chapter{Simple Graphics Package}\label{appendix}\index{Simple Graphics Package}
4 \setheader{{\it Appendix \thechapter}}{}{}{\ctsimheadtitle}{}{{\it Appendix \thechapter}}%
5 \ctsimfooter%
6
7
8 Simple Graphics Package was created in 1980 by Kevin Rosenberg and
9 is modelled after the graphics library in Foley and van
10 Dam\cite{FOLEY82}. It is designed to be platform-independent.
11
12 \section{Flowchart}
13 Master coordinate (MC) level \\
14 $\hspace{3cm} \downarrow$ \\
15 Apply \emph{Current transformation matrix} \\
16 $\hspace{3cm} \downarrow$ \\
17 World coordinate (WC) level \\
18 $\hspace{4cm} \downarrow$ \\
19 Clipping against Window \\
20 $\hspace{3cm} \downarrow$ \\
21 Convert to Normalized device coordinates (NDC) \\
22 $\hspace{3cm}  \downarrow$ \\
23 Clipping against Viewport \\
24 $\hspace{3cm}  \downarrow$ \\
25 Convert to Physical device coordinates (PDC) \\
26
27
28 \section{Functions}%
29
30 \subsection{State functions}
31 \begin{twocollist}
32 \twocolitem{\texttt{eraseWindow()}}{Clears the screen}
33 \twocolitem{\texttt{setColor(color)}}{Set current pen color}
34 \twocolitem{\texttt{setLinestyle(style)}}{Set current pen style}
35 \twocolitem{\texttt{setLinewidth(width)}}{Set current pen width}
36 \twocolitem{\texttt{setTextColor(foreground, background)}}{Set text colors}
37 \twocolitem{\texttt{setMarker(type, color)}}{Set marker attibutes}
38 \twocolitem{\texttt{setRasterOp(rasterOp)}}{Set raster operator}
39 \end{twocollist}
40
41
42 \subsection{Master coordinate functions}
43 \begin{twocollist}
44 \twocolitem{\texttt{setWindow(xmin, ymin, xmax, ymax)}}{Set window for world
45 coordinates}
46 \twocolitem{\texttt{moveAbs(x, y)}}{Move graphics cursor to absolute position}
47 \twocolitem{\texttt{moveRel(dx, dy)}}{Move graphics cursor relative to current position}
48 \twocolitem{\texttt{pointAbs(x, y)}}{Draw point at current position}
49 \twocolitem{\texttt{pointRel(dx, dy)}}{Draw point relative to current position}
50 \twocolitem{\texttt{lineAbs(x, y)}}{Draw line from current position to
51 absolute position}
52 \twocolitem{\texttt{lineRel(dx, dy)}}{Draw line from current position to position
53 relative to current position}
54 \twocolitem{\texttt{markerAbs(x,y)}}{Draw marker at current position}
55 \twocolitem{\texttt{markerRel(dx,dy)}}{Draw marker relative to current position}
56 \twocolitem{\texttt{polylineAbs(x[], y[], n)}}{Draw a series of lines to absolute position}
57 \twocolitem{\texttt{polylineRel(dx[], dy[], n)}}{Draw series of lines relative to current position}
58 \twocolitem{\texttt{drawString(str)}}{Draw text string at current positon}
59 \twocolitem{\texttt{drawCircle(r}}{Draw circle at current positon}
60 \twocolitem{\texttt{drawArc(r,start,stop)}}{Draw arc with center at current positon}
61 \twocolitem{\texttt{drawRect(xmin,ymin,xmax,ymax)}}{Draw rectangle}
62 \end{twocollist}
63
64 \subsection{Normalized coordinate functions}%
65 \begin{twocollist}
66 \twocolitem{\texttt{Viewport(xmin, ymin, xmax, ymax)}}{Viewport for window
67 in NDC}
68 \twocolitem{\texttt{stylus(x, y, beam)}}{Draw a line from current
69 position}
70 \twocolitem{\texttt{markerNDC(xndc, yndc)}}{Draw marker at NDC position}
71 \end{twocollist}
72
73 \subsection{Master coordinate to World coordinate transformations}%
74 These transformation functions operate on the \emph{Current transformation
75 matrix} (CTM).
76
77 \begin{twocollist}
78 \twocolitem{\texttt{clearCTM()}}{Sets the CTM to an identity matrix}
79 \twocolitem{\texttt{preTranslate(x,y)}}{Apply translation to CTM}
80 \twocolitem{\texttt{postTranslate(x,y)}}{Apply translation to CTM}
81 \twocolitem{\texttt{preScale(x,y)}}{Apply scale to CTM}
82 \twocolitem{\texttt{postScale(x,y)}}{Apply scale to CTM}
83 \twocolitem{\texttt{preRotate(angle)}}{Apply rotation to CTM}
84 \twocolitem{\texttt{postRotate(angle)}}{Apply rotation to CTM}
85 \twocolitem{\texttt{preShear(x,y)}}{Apply shear to CTM}
86 \twocolitem{\texttt{postShear(x,y)}}{Apply shear to CTM}
87 \end{twocollist}
88
89 \subsection{Coordinate transformation functions}%
90 \begin{twocollist}
91 \twocolitem{\texttt{transformMCtoNDC(\&x,\&y)}}{Convert from master
92 coordinates to NDC}
93 \twocolitem{\texttt{transformNDCtoMC(\&x,\&y)}}{Convert from NDC to master
94 coordinates}
95 \end{twocollist}
96
97 \section{Coordinate Mapping}
98
99 \subsection{Dimensions}
100 Window (World Coordinates):  $X_{wmin}, X_{wmax}, Y_{wmin}, Y_{wmax}$ \\
101 Viewport (Normalized Device Coordinates): $X_{vmin}, X_{vmax}, Y_{vmin}, Y_{vmax}$\\
102 Physical (Physicial Device Coordinates): $X_{pmax}, Y_{pmax}$\\
103
104 \subsection{Formulas}
105 To convert from Master coordinates to World coordinates: \\
106 Apply current transformation matrix
107
108 To convert from WC to NDC:\\
109 \begin{equation}
110 X_{ndc} = X_{vmin} + (X_{vmax} - X_{vmin})  (X_{wc} - X_{wmin}) / (X_{wmax} - X_{wmin})
111 \end{equation}
112 \begin{equation}
113 Y_{ndc} = Y_{vmin} + (Y_{vmax} - Y_{vmin}) (Y_{wc} - Y_{wmin}) / (Y_{wmax} - Y_{wmin})
114 \end{equation}
115
116 To convert from NDC to PDC:
117 \begin{equation}
118      X_{pdc} = X_{ndc} X_{pmax}
119 \end{equation}
120 \begin{equation}
121      Y_{pdc} = X_{ndc} Y_{pmax}
122 \end{equation}