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