Hill CH 3 Ed 3
Hill CH 3 Ed 3
sin(x ) sinc( x ) x
Sinc(0) = 1 by definition. Interesting parts of the function are in -4.0 x 4.0.
Mapping Windows
Windows are described by their left, top, right, and bottom values, w.l, w.t, w.r, w.b. Viewports are described by the same values: v.l, v.t, v.r, v.b, but in screen window coordinates.
Mapping (2)
We can map any aligned rectangle to any other aligned rectangle.
If the aspect ratios of the 2 rectangles are not the same, distortion will result.
y W.t W.l W.r x W.b window V.b viewport sx Screen window V.t V.l V.r
sy
Window-to-Viewport Mapping
We want our mapping to be proportional: for example, if x is of the way between the left and right world window boundaries, then the screen x (sx) should be of the way between the left and right viewport boundaries.
Summary: sx = A x + C, sy = B y + D, with V. r V. l
W. r W. l V. t V. b B , D V. b B W. b W. t W. b A , C V. l A W. l
Applications (continued)
Tiling A was set up by the following code:
setWindow(0, 640.0, 0, 440.0); // set a fixed window for (int i = 0; i < 5; i++) // for each column for (int j = 0; j < 5; j++){ // for each row {glViewport (i*64, j*44,64, 44); // set the next viewport drawPolylineFile("dino.dat"); // draw it again }
Tiling B requires more effort: you can only turn a window upside down, not a viewport.
Applications (continued)
Code for Tiling B
for (int i = 0; i < 5; i++) // for each column for (int j = 0; j < 5; j++){ // for each row if ((i + j) % 2 == 0){ setWindow(0.0, 640.0, 0.0, 440.0); } else { setWindow(0.0, 640.0, 440.0, 0.0); // upside-down } glViewport (i*64, j*44,64, 44); // no distortion drawPolylineFile("dino.dat"); }
Application (continued)
The figure is a collection of concentric hexagons of various sizes, each rotated slightly with respect to the previous one. It is drawn by a function called hexSwirl (); The figure showed 2 choices of world windows. We can also use world windows for zooming and roaming (panning).
Roaming (Panning)
To roam, or pan, we move a viewport through various portions of the world. This is easily accomplished by translating the window to a new position. What sequence of windows would you want in order to roam through the image?
Clipping Lines
We want to draw only the parts of lines that are inside the world window. To do this, we need to replace line portions outside the window by lines along the window boundaries. The process is called clipping the lines.
Clipping (2)
The method we will use is called CohenSutherland clipping. There are 2 trivial cases: a line AB totally inside the window, which we draw all of, and a line CD totally outside the window, which we do not draw at all.
Clipping (3)
For all lines, we give each endpoint of the line a code specifying where it lies relative to the window W:
Clipping (4)
The diagram below shows Boolean codes for the 9 possible regions the endpoint lies in (left, above, below, right).
Clipping (5)
A line consists of 2 endpoints (vertices), P1 and P2. If we do not have a trivial case, we must alter the vertices to the points where the line intersects the window boundaries (replace P1 by A).
Clipping (6)
In the diagram, d/dely = e/delx (similar triangles). Obviously, A.x = W.r. Also, delx = p1.x p2.x, dely = p1.y p2.y and e = p1.x W.r. So A.y = p1.y d.
Clipping Pseudocode
Complete pseudocode for the CohenSutherland Line Clipper is shown in Fig. 3.21.
Regular Polygons
Koch Curves
Successive generations of the Koch curve are denoted K0, K1, K2, The 0-th generation shape K0 is just a horizontal line of length 1. The curve K1 is created by dividing the line K0 into three equal parts, and replacing the middle section with a triangular bump having sides of length 1/ 3. The total line length is evidently 4 / 3.
K2:
Parametric Curves
Three forms of equation for a given curve:
Explicit: e.g., y = m*x + b Implicit: F(x, y) = 0; e.g., y m*x b = 0 Parametric: x = x(t), y = y(t), t a parameter; frequently, 0 t 1. E.g., P = P1*(1-t) + P2*t. P1 and P2 are 2D points with x and y values. The parametric form is x = x1*(1-t) + x2*t and y = y1*(1-t) + y2*t.
Shapes
Cardioid, 2 rose curves, Archimedean spiral