3 \chapter{Simple Graphics Package}\label{appendix}\index{Simple Graphics Package}
4 \setheader{{\it Appendix \thechapter}}{}{}{\ctsimheadtitle}{}{{\it Appendix \thechapter}}%
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.
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)}
31 \subsection{Master coordinate functions}
33 \twocolitem{\texttt{setWindow(xmin, ymin, xmax, ymax)}}{Set window for world
35 \twocolitem{\texttt{moveAbs(x, y)}}{Move graphics cursor to absolute position}
36 \twocolitem{\texttt{moveRel(dx, dy)}}{Move graphics cursor relative to current position}
37 \twocolitem{\texttt{pointAbs(x, y)}}{Draw point at current position}
38 \twocolitem{\texttt{pointRel(dx, dy)}}{Draw point relative to current position}
39 \twocolitem{\texttt{lineAbs(x, y)}}{Draw line from current position to
41 \twocolitem{\texttt{lineRel(dx, dy)}}{Draw line from current position to position
42 relative to current position}
43 \twocolitem{\texttt{markerAbs(x,y)}}{Draw marker at current position}
44 \twocolitem{\texttt{markerRel(dx,dy)}}{Draw marker relative to current position}
45 \twocolitem{\texttt{polylineAbs(x[], y[], n)}}{Draw a series of lines to absolute position}
46 \twocolitem{\texttt{polylineRel(dx[], dy[], n)}}{Draw series of lines relative to current position}
47 \twocolitem{\texttt{drawString(str)}}{Draw text string at current positon}
48 \twocolitem{\texttt{drawCircle(r)}}{Draw circle at current positon}
49 \twocolitem{\texttt{drawArc(r,start,stop)}}{Draw arc with center at current positon}
50 \twocolitem{\texttt{drawRect(xmin,ymin,xmax,ymax)}}{Draw rectangle}
53 \subsection{Normalized coordinate functions}%
55 \twocolitem{\texttt{Viewport(xmin, ymin, xmax, ymax)}}{Viewport for window
57 \twocolitem{\texttt{stylus(x, y, beam)}}{Draw a line from current
59 \twocolitem{\texttt{markerNDC(xndc, yndc)}}{Draw marker at NDC position}
62 \subsection{Master coordinate to World coordinate transformations}%
63 These transformation functions operate on the \emph{Current transformation
67 \twocolitem{\texttt{clearCTM()}}{Sets the CTM to an identity matrix}
68 \twocolitem{\texttt{preTranslate(x,y)}}{Apply translation to CTM}
69 \twocolitem{\texttt{postTranslate(x,y)}}{Apply translation to CTM}
70 \twocolitem{\texttt{preScale(x,y)}}{Apply scale to CTM}
71 \twocolitem{\texttt{postScale(x,y)}}{Apply scale to CTM}
72 \twocolitem{\texttt{preRotate(angle)}}{Apply rotation to CTM}
73 \twocolitem{\texttt{postRotate(angle)}}{Apply rotation to CTM}
74 \twocolitem{\texttt{preShear(x,y)}}{Apply shear to CTM}
75 \twocolitem{\texttt{postShear(x,y)}}{Apply shear to CTM}
78 \subsection{Coordinate transformation functions}%
80 \twocolitem{\texttt{transformMCtoNDC(\&x,\&y)}}{Convert from master
82 \twocolitem{\texttt{transformNDCtoMC(\&x,\&y)}}{Convert from NDC to master
86 \subsection{State functions}
88 \twocolitem{\texttt{eraseWindow()}}{Clears the screen}
89 \twocolitem{\texttt{setColor(color)}}{Set current pen color}
90 \twocolitem{\texttt{setLinestyle(style)}}{Set current pen style}
91 \twocolitem{\texttt{setLinewidth(width)}}{Set current pen width}
92 \twocolitem{\texttt{setTextColor(foreground, background)}}{Set text colors}
93 \twocolitem{\texttt{setMarker(type, color)}}{Set marker attibutes}
94 \twocolitem{\texttt{setRasterOp(rasterOp)}}{Set raster operator}
97 \section{Coordinate Mapping}
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}$\\
104 \subsection{Formulas}
105 To convert from Master coordinates to World coordinates: \\
106 \centerline{Apply \emph{current transformation matrix}}
108 To convert from WC to NDC:\\
110 X_{ndc} = X_{vmin} + (X_{vmax} - X_{vmin}) (X_{wc} - X_{wmin}) / (X_{wmax} - X_{wmin})
113 Y_{ndc} = Y_{vmin} + (Y_{vmax} - Y_{vmin}) (Y_{wc} - Y_{wmin}) / (Y_{wmax} - Y_{wmin})
116 To convert from NDC to PDC:
118 X_{pdc} = X_{ndc} X_{pmax}
121 Y_{pdc} = X_{ndc} Y_{pmax}