c25c257638428656f2d10772a88b7efe61d5bf94
[ctsim.git] / doc / ctsim-appendix.tex
1 \chapter{Appendix}\label{appendix}\index{Appendix}%
2 \setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
3 \setfooter{\thepage}{}{}{}{}{\thepage}%
4
5 \section{Simple Graphics Package}\index{Simple Graphics Package}%
6
7 \subsection{Overview}%
8 Simple Graphics Package was creates in 1983 by Kevin Rosenberg and is modelled after the graphics library in Foley and van Dam\cite{FOLEY82}.
9
10 \begin{verbatim}
11                        +------------------------+
12                        | World Coordinate level |
13                        +-----------+------------+
14                                    |
15                      +-------------+-------------+
16                      | Clipping against Window() |
17                      +-------------+-------------+
18                                    |
19                       +------------+-------------+
20                       | Convert to Normalized    |
21                       | device coordinates (NDC) |
22                       +------------+-------------+
23                                    |
24                      +-------------+-------------+
25                      | Clipping against Viewport |
26                      +-------------+-------------+
27                                    |
28                       +------------+-------------+
29                       | Convert to Physical      |
30                       | device coordinates (PDC) |
31                       +--------------------------+
32 \end{verbatim}
33
34 \subsection{Functions}%
35
36 \subsubsection{World Coordinate Level}%
37      initgrf2 ()                         Initialize 2 dimensional graphics\\
38      termgrf2 ()                         Terminate 2 dimensional graphics\\
39      Window  (xmin, ymin, xmax, ymax)   Set window for world coordinates\\
40      Viewport (xmin, ymin, xmax, ymax)   Viewport for window in NDC\\
41      MoveAbs (x, y)                     Move graphics cursor\\
42      MoveRel (dx, dy)\\
43      PointAbs (x, y)                      Plot point at current position\\
44      PointRel (dx, dy)\\
45      LineAbs2 (x, y)             Draw line from current point to point\\
46      LineRel2 (dx, dy)\\
47      MarkerAbs2 (x, y)                     Draw marker at current position\\
48      MarkerRel2 (dx, dy)\\
49      PolylineAbs (x[], y[], n)             Draw a set of lines\\
50      PolylineRel (dx[]. dy[]. n)\\
51      wc\_to\_ndc (xwc, ywc, xndc, yndc)    Convert from world coord to NDC\\
52      ndc\_to\_wc (xndc, yndc, xwc, ywc)    Convert from NDC to world coord\\
53      DrawText (str)                      Draw text string at current positon\\
54
55      INTERNAL:\\
56           calc\_map ()                        Calculate wc to ndc factors\\
57           clip(rectangle[4], x1, y1, x2, y2) Clip a line againt rectangle\\
58
59
60 \subsubsection{Normalized Coordinate level}%
61      stylus (x, y, beam)                 Draw a line from current position\\
62      setColor (color)            Set current drawing color\\
63      setLinestyle (style)                Set current line style\\
64      setLinewidth (width)                Set current line width\\
65      setTextColor (foreground, background) If back=-1, then transparent \\
66
67      setMarker (type, color)      Set marker attibutes\\
68      markerNDC (xndc, yndc)                Draw marker at NDC position\\
69
70 \subsection{Coordinate Mapping}%
71
72 \subsubsection{Mapping from world coordinates to physical device coordinates}%
73
74 Window (World Coordinates):   xwmin, xwmax, ywmin, ywmax \\
75 Viewport (Normalized Device Coordinates): xvmin, xvmax, yvmin, yvmax\\
76 Physical (Physicial Device Coordinates): xpmax, ypmax\\
77
78 To convert from WC to NDC:\\
79 \begin{equation}
80      X_{ndc} = X_vmin + (X_wc - X_wmin) / (X_wmax - X_wmin)
81 \end{equation}
82 \begin{equation}
83      Y_{ndc} = Y_vmin + (Y_wc - Y_wmin) / (Y_wmax - Y_wmin)
84 \end{equation}
85 To convert from NDC to PDC:
86 \begin{equation}
87      X_{pdc} = X_{ndc} X_{pmax}
88 \end{equation}
89 \begin{equation}
90      Y_{pdc} = X_{ndc} Y_{pmax}
91 \end{equation}
92
93 So, for each device set up the following composite transformation:\\
94 \begin{equation}
95      x_{pdc} = x_{pmax} (x_{vmin} + (x_{wc} - x_{wmin}) / (x_{wmax} - x_{wmin}))
96 \end{equation}
97 \begin{equation}
98      y_{pdc} = y_{pmax} (y_{vmin} + (y_{wc} - y_{wmin}) / (y_{wmax} - y_{wmin}))
99 \end{equation}
100 \begin{equation}
101      X_{pdc} = X_{pmax} X_{vmin} + ((X_{wc} \- X_{wmin})  X_{pmax})/(X_{wmax} \- X_{wmin}))
102 \end{equation}
103 \begin{equation}
104      X_{pdc} = X_{add} + (X_wc - X_{sub})  X_{fract}
105 \end{equation}