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