0% found this document useful (0 votes)
86 views10 pages

Windowing: Portions of An Image or Portions of A Drawing Is Called Windowing

Windowing in computer graphics refers to selecting a rectangular area or "window" in the user's coordinate system to view a portion of a larger image or drawing. The window is defined by its left, right, bottom, and top boundaries and acts like a viewport into the larger space. Bresenham's line algorithm uses integer math to efficiently determine the optimal pixel locations to represent a line by incrementing either the x or y coordinate by one each iteration based on the slope of the line. Bresenham's circle algorithm applies the same principles to efficiently draw circles by plotting points moving outwards in 1/8th increments and reflecting across axes.

Uploaded by

Anupa Chandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views10 pages

Windowing: Portions of An Image or Portions of A Drawing Is Called Windowing

Windowing in computer graphics refers to selecting a rectangular area or "window" in the user's coordinate system to view a portion of a larger image or drawing. The window is defined by its left, right, bottom, and top boundaries and acts like a viewport into the larger space. Bresenham's line algorithm uses integer math to efficiently determine the optimal pixel locations to represent a line by incrementing either the x or y coordinate by one each iteration based on the slope of the line. Bresenham's circle algorithm applies the same principles to efficiently draw circles by plotting points moving outwards in 1/8th increments and reflecting across axes.

Uploaded by

Anupa Chandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

WINDOWING In general, window is an opening through which part of the outside world can be seen.

But let us now try to understand what the term window actually means in the context of computer graphics. Many applications of computer graphics give the user the impression of looking through a window at a very large picture. Often, computer graphics system is used in design application because it can easily and accurately create, store and modify very complex drawings. When drawings are too complex, they become difficult to read. In such situations it is useful to display only those portions of the drawing that are of immediate interest. This gives the effect of looking at the image through a window. This method for selecting and enlarging portions of an image or portions of a drawing is called windowing.

Figure illustrating the concept of WINDOWING and its mathematical formulation. In the above figure XL and XH specify the left and right boundaries of the window respectively. YL and YH specify the bottom and top window boundaries respectively.

Typically when we think about a window, we think about some rectangular entity. This will be the same case in the context of computer graphics. A window in computer graphics refers to a rectangular area in the users own coordinate system known as the world coordinate system. It is very important to note the following: "window coordinates" means "user coordinates" means "world coordinates". A window is usually specified using following parameters, (1)XL (2)XH (3)YL (4)YH Where XL and XH are abscissa, YL and YH are ordinates. An algorithm for setting window dimensions is given below. SET_WINDOW (XL, XH, YL, YH) Arguments XL, XH are left and right window boundaries respectively YL, YH are bottom and top window boundaries respectively Global WXL_HOLD, WXH_HOLD, WYL_HOLD, WYH_HOLD are storage for window boundaries BEGIN IF XL>=XH OR YL>=YH THEN RETURN ERROR BAD WINDOW; WXL_HOLD = XL; WXH_HOLD= XH; WYL_HOLD = YL; WYH_HOLD= YH; RETURN END

BRESENHAMS LINE ALGORITHM Bresenhams line algorithm uses only integer addition and subtraction and multiplication by 2, and we know that computer can perform the operations of integer addition and subtraction very rapidly. The computer is also time efficient when performing integer multiplication by powers of 2. Therefore this is an efficient algorithm for generating line. The basic principle of Bresenhams line algorithm is to select the optimum raster locations to represent a straight line. To accomplish this the algorithm always increments either x or y by one unit depending on the slope of the line. The increment in the other variable is determined by examining distance between the actual line location and the nearest pixel. This distance is called decision variable or error.

As shown in the above figure, the line doesnt pass through all raster points (pixels). It passes through raster point (0,0) and subsequently crosses three pixels. It is seen that the intercept of the line with the x=1 is closer to the line y=0, i.e. pixel (1,0) than to the line y=1, i.e. pixel (1,1). Hence in this case the raster point at (1,0) better represents the path of the line than that at (1,1). The intercept of the line with the line x=2 is close to the line y=1, i.e. pixel (2,1) than to the line y=0, i.e. pixel (2,0). Hence the raster point at (2,1) better represents path of the line. In mathematical terms, error or decision variable is defined as e = DB-DA or e = DA-DB

Let us define e = DB-DA. Now if e>0, then it implies that DB>DA, i.e. the pixel above the line is closer to the true line. If DA>DB (e<0) then we can say that the pixel below the line is closer to the true line. Thus by checking only the sign of error term it is possible to determine the better pixel to represent the line path. The error term is initially set as, e= 2*y-x Then according to the value of e following actions are taken. while (e>=0) { y=y+1 e=e-2*x } x=x+1 e=e+2*y When e>=0, error is initialized with e= e-2*x. This is continued till error is negative. In each iteration y is incremented by 1. When e<0, error is initialized to e=e+2*y. In both the cases x is incremented by 1. ALGORITHM (1) Read the line end points (x1,y1) and (x2,y2) such that they are not equal. [if equal then plot that point and exit] (2) x = |x2-x1 |and y = |y2-y1| (3) Initialize the starting point x=x1, y=y1 (4) Initialize value of decision variable or error to compensate for non-zero intercepts e= 2*y-x (5) Initialize counter i=1 (6) Plot(x,y) (7) while (e>=0) {

y=y+1 e=e-2*x } x=x+1 e=e+2*y (8) Increment the counter i=i+1 (9) If (i <=x) then go to step 6. (10) Stop

BRESENHAMS CIRCLE ALGORITHM Bresenham_Circle ( xc, yc, r) Description: Here xc and yc denote the x coordinate and y coordinate of the center of the circle. r is the radius. 1. Set x = 0 and y = r 2. Set D = 3 2r 3. Repeat while (x < y) 4. Call Draw_Circle(xc, yc, x, y) 5. Set x = x + 1 6. If (D < 0) Then 7. D = D + 4x + 6 8. Else 9. Set y = y 1 10. D = D + 4(x y) + 10 [End of If] 11. Call Draw_Circle(xc, yc, x, y)

[End of While] 12. Stop Draw_Circle (xc, yc, x, y): 1. Call PutPixel(xc + x, yc, + y) 2. Call PutPixel(xc - x, yc, + y) 3. Call PutPixel(xc + x, yc, - y) 4. Call PutPixel(xc - x, yc, - y) 5. Call PutPixel(xc + y, yc, + x) 6. Call PutPixel(xc - y, yc, + x) 7. Call PutPixel(xc + y, yc, - x) 8. Call PutPixel(xc - y, yc, - x) 9. Stop

BRESENHAMS CIRCLE DRAWING ALGORITHM The Bresenhams circle drawing algorithm considers the eight way symmetry of the circle to generate it. It plots 1/8th part of the circle, i.e. from 90 to 45, as shown in figure. As the circle is drawn from 90 to 45, the x moves in positive direction and y moves in negative direction. To achieve best approximation to the true circle we have to select those pixels in the raster that fall the least distance from true circle. If two points are generated from 90 to 45, each new point closest to the true circle can be found by applying either of the two options: (1)Increment in positive x direction by 1 unit (2) Increment in positive x direction and negative y direction both by 1 unit

Let us assume point P in the above figure as the last scan converted pixel. Now we have two options either to choose pixel A or pixel B. Let DA and DB represent the

distances of pixels A and B from the origin. The closer pixel among these two can be determined as follows. DA = [(xi+1)2 + (yi)2]1/2 DB = [(xi+1)2 + (yi-1)2]1/2 Now the distances of pixels A and B from the true circle are given as A = DA- r and B = DB - r However, to avoid square root term in derivation of decision variable, i.e. to simplify the computation and to make algorithm more efficient A and B are defined as A = DA2 - r2 and B = DB2 - r2 Also we can observe that A is always positive and B is always negative. Therefore we can define a decision variable di as di = A + B and we can say that, if di<0() then only x is incremented; otherwise x is incremented in positive direction and y is incremented in negative direction i.e., For di < 0, For di >= 0, xi+1 = xi + 1 xi+1 = xi + 1 and yi+1 = yi 1

The equation for di at starting point i.e. at x=0 and y=r is obtained as follows di = A + B di = DA2 - r2 + DB2 - r2 di = (xi+1)2 + (yi)2 r2 + (xi+1)2 + (yi-1)2 r2 di = 1 + r2 - r2 + 1 + r2 - 2 r + 1 - r2 di = 3 - 2 r Similarly, the equations for di+1 for both the cases are given as For di < 0, di+1 = di + 4xi + 6

For di >= 0,

di+1 = di + 4(xi - yi) + 10

ALGORITHM TO PLOT 1/8TH OF THE CIRCLE


1. 2. 3. 4. Read the radius (r) of the circle. d = 3 - 2 r [Initialize the decision variable] x = 0, y = r [Initialize starting point] do { plot (x,y) if(d<0) then { d = d + 4x +6 } else { d = d + 4(x-y) +10 y = y-1 } x=x+1 } while (x<y) 5. Stop The remaining portion of circle can be drawn by reflecting point about y axis, x axis and about origin. Therefore by adding seven more plot command in step 4 of the algorithm, the circle can be plotted. The remaining seven plot commands are : plot(y,x) plot(y,-x) plot(x,-y) plot(-x,-y) plot(-y,-x) plot(-y,x) plot(-x,y)

You might also like