0% found this document useful (0 votes)
56 views39 pages

Chapter Four

Uploaded by

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

Chapter Four

Uploaded by

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

Chapter 4

Computer Graphics Window:

The method of selecting and enlarging a portion of a drawing is called windowing.


The area chosen for this display is called a window. The window is selected by world-
coordinate.

Sometimes we are interested in some portion of the object and not in full object. So
we will decide on an imaginary box. This box will enclose desired or interested area
of the object. Such an imaginary box is called a window.

Viewport: An area on display device to which a window is mapped [where it is to


displayed].

Basically, the window is an area in object space. It encloses the object. After the user
selects this, space is mapped on the whole area of the viewport. Almost all 2D and
3D graphics packages provide means of defining viewport size on the screen. It is
possible to determine many viewports on different areas of display and view the
same object in a different angle in each viewport.

The size of the window is (0, 0) coordinate which is a bottom-left corner and toward
right side until window encloses the desired area. Once the window is defined data
outside the window is clipped before representing to screen coordinates. This
process reduces the amount of data displaying signals.

The window size of the Tektronix 4.14 tube in Imperial College contains 4.96 points
horizontally and 3072 points vertically.

Viewing transformation or window to viewport transformation or windowing


transformation: The mapping of a part of a world-coordinate scene to device
coordinates is referred to as a viewing transformation etc.

Viewing transformation in several steps:

First, we construct the scene in world coordinate using the output primitives and
attributes.

To obtain a particular orientation, we can set up a 2-D viewing coordinate system in


the window coordinate plane and define a window in viewing coordinates system.
ADVERTISEMENT

Once the viewing frame is established, are then transform description in world
coordinates to viewing coordinates.

Then, we define viewport in normalized coordinates (range from 0 to 1) and map the
viewing coordinates description of the scene to normalized coordinates.

At the final step, all parts of the picture that (i.e., outside the viewport are dipped,
and the contents are transferred to device coordinates).

By changing the position of the viewport:We can view objects at different


locations on the display area of an output device as shown in fig:

By varying the size of viewports: We can change the size and proportions of
displayed objects. We can achieve zooming effects by successively mapping different-
sized windows on a fixed-size viewport.

As the windows are made smaller, we zoom in on some part of a scene to view details
that are not shown with larger windows.

Computer Graphics Window to Viewport Co-ordinate Transformation

Once object description has been transmitted to the viewing reference frame, we
choose the window extends in viewing coordinates and selects the viewport limits in
normalized coordinates.

Object descriptions are then transferred to normalized device coordinates:

We do this thing using a transformation that maintains the same relative placement
of an object in normalized space as they had in viewing coordinates.
If a coordinate position is at the center of the viewing window:

It will display at the center of the viewport.

Fig shows the window to viewport mapping. A point at position (xw, yw) in window
mapped into position (xv, yv) in the associated viewport.

In order to maintain the same relative placement of the point in the viewport as in
the window, we require:

Solving these impressions for the viewport position (xv, yv), we have

xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy ...........equation 2

Where scaling factors are

Equation (1) and Equation (2) can also be derived with a set of transformation that
converts the window or world coordinate area into the viewport or screen coordinate
area. This conversation is performed with the following sequence of transformations:

1. Perform a scaling transformation using a fixed point position (xwmin,ywmin) that


scales the window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport. Relative
proportions of objects are maintained if the scaling factors are the same
(sx=sy).

From normalized coordinates, object descriptions are mapped to the various display
devices.

Any number of output devices can we open in a particular app, and three windows
to viewport transformation can be performed for each open output device.

This mapping called workstation transformation (It is accomplished by selecting a


window area in normalized space and a viewport area in the coordinates of the
display device).

As in fig, workstation transformation to partition a view so that different parts of


normalized space can be displayed on various output devices).

Matrix Representation of the above three steps of Transformation:

Step1:Translate window to origin 1


Tx=-Xwmin Ty=-Ywmin

Step2:Scaling of the window to match its size to the viewport


Sx=(Xymax-Xvmin)/(Xwmax-Xwmin)
Sy=(Yvmax-Yvmin)/(Ywmax-Ywmin)
Step3:Again translate viewport to its correct position on screen.
Tx=Xvmin
Ty=Yvmin

Above three steps can be represented in matrix form:


VT=T * S * T1

T = Translate window to the origin

S=Scaling of the window to viewport size

T1=Translating viewport on screen.

Viewing Transformation= T * S * T1

Advantage of Viewing Transformation:

We can display picture at device or display system according to our need and choice.

Note:

o World coordinate system is selected suits according to the application program.


o Screen coordinate system is chosen according to the need of design.
o Viewing transformation is selected as a bridge between the world and screen
coordinate.

Computer Graphics Zooming

Zooming is a transformation often provided with an imaginary software. The


transformation effectively scales down or blows up a pixel map or a portion of it with
the instructions from the user. Such scaling is commonly implemented at the pixel
level rather than at the coordinates level. A video display or an image is necessarily a
pixel map, i.e., a collection of pixels which are the smallest addressable elements of a
picture. The process of zooming replicates pixels along successive scan lines.

Example: for a zoom factor of two

Each pixel value is used four times twice on each of the two successive scan lines.

Figure shows the effect of zooming by a factor of 2.


Such integration of pixels sometimes involves replication using a set of ordered
patterns, commonly known as Dithering.

The two most common dither types are:

o Ordered dither.
o Random dither.

There are widely used, especially when the grey levels (share of brightness) are
synthetically generated.

Computer Graphics Panning

The process of panning acts as a qualifier to the zooming transformation. This step
moves the scaled up portion of the image to the center of the screen and depending
on the scale factor, fill up the entire screen.

Advantage:

Effective increase in zoom area in all four direction even if the selected image portion
(for zooming) is close to the screen boundary.

Inking:

If we sample the position of a graphical input device at regular intervals and display
a dot at each sampled position, a trial will be displayed of the movement of the
device.This technique which closely simulates the effect of drawing on paper is called
Inking.

For many years the primary use of inking has been in conjunction with online
character-recognition programs.
Scissoring:

In computer graphics, the deleting of any parts of an image which falls outside of a
window that has been sized and laid the original vision ever. It is also called the
clipping.

Clipping:

When we have to display a large portion of the picture, then not only scaling &
translation is necessary, the visible part of picture is also identified. This process is
not easy. Certain parts of the image are inside, while others are partially inside. The
lines or elements which are partially visible will be omitted.

For deciding the visible and invisible portion, a particular process called clipping is
used. Clipping determines each element into the visible and invisible portion. Visible
portion is selected. An invisible portion is discarded.

Types of Lines:

Lines are of three types:

1. Visible: A line or lines entirely inside the window is considered visible


2. Invisible: A line entirely outside the window is considered invisible
3. Clipped: A line partially inside the window and partially outside is clipped. For
clipping point of intersection of a line with the window is determined.
Clipping can be applied through hardware as well as software. In some computers,
hardware devices automatically do work of clipping. In a system where hardware
clipping is not available software clipping applied.

Following figure show before and after clipping


The window against which object is clipped called a clip window. It can be curved or
rectangle in shape.

Applications of clipping:

1. It will extract part we desire.


2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
5. Operations related to the pointing of an object.
6. For deleting, copying, moving part of an object.

Clipping can be applied to world co-ordinates. The contents inside the window will
be mapped to device co-ordinates. Another alternative is a complete world co-
ordinates picture is assigned to device co-ordinates, and then clipping of viewport
boundaries is done.

Types of Clipping:

1. Point Clipping
2. Line Clipping
3. Area Clipping (Polygon)
4. Curve Clipping
5. Text Clipping
6. Exterior Clipping

Point Clipping:

Point Clipping is used to determining, whether the point is inside the window or not.
For this following conditions are checked.

1. x ≤ xmax
2. x ≥ xmin
3. y ≤ ymax
4. y ≥ ymin

The (x, y) is coordinate of the point. If anyone from the above inequalities is false,
then the point will fall outside the window and will not be considered to be visible.
Program1:

To implement Point Clipping:

1. #include<stdio.h>
2. #include<conio.h>
3. #include<graphics.h>
4. inttlx,tly,brx,bry,px,py;
5. void point_clip()
6. {
7. intwxmin,wymin,wxmax,wymax;
8. wxmin=tlx;
9. wxmax=brx;
10. wymin=tly;
11. wymax=bry;
12. if(px>=wxmin&&px<=wxmax)
13. if(py>=wymin&&py<=wymax)
14. putpixel(px,py,RED);
15. getch();
16. closegraph();
17. }
18. void main()
19. {
20. intgd=DETECT,gm,xc,yc,r;
21. clrscr();
22. printf("Enter the top left coordinate");
23. scanf("%d%d",&tlx,&tly);
24. printf("Enter the bottom right coordinate");
25. scanf("%d%d",&brx,&bry);
26. printf("\n Enter the point");
27. scanf("%d%d",&px,&py);
28. initgraph(&gd,&gm,"c:\\tc\\bgi");
29. setbkcolor(BLUE);
30. setcolor(RED);
31. rectangle(tlx,tly,brx,bry);
32. point_clip();
33. }

Output:
Program2:

To implement point clipping with respect to rectangular window:

1. #include<stdio.h>
2. #include<conio.h>
3. #include<graphics.h>
4. void main()
5. {
6. int gm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;
7. clrscr();
8. detectgraph(&gm,&gr);
9. initgraph(&gm,&gr,"c:\\tc\\BGI");
10. printf("Enter the clipmin coordinate :\n");
11. scanf("%d%d",&xcmin,&ycmin);
12. printf("Enter the clipmax coordinate :\n");
13. scanf("%d%d",&xcmax,&ycmax);
14. rectangle(xcmin,ycmax,xcmax,ycmin);
15. printf("Enter the coordinate of the point:\n");
16. scanf("%d%d",&x,&y);
17. detectgraph(&gm,&gr);
18. initgraph(&gm,&gr,"c:\\tc\\BGI");
19. putpixel(x,y,15);
20. printf("\n1.Point clipping\n2.Exit\nEnter your choice:\n");
21. scanf("%d",&c);
22. switch(c)
23. {
24. case 1:
25. detectgraph(&gm,&gr);
26. initgraph(&gm,&gr,"d:\\tc\\BGI");
27. rectangle (xcmin,ycmax,xcmax,ycmin);
28. printf("*******POINT CLIPPING******\n");
29. if ((xcmin<x) && (x<xcmax))
30. {
31. if ((ycmin<y) && (y<ycmax))
32. {
33. printf("The point is inside the clip window\n");
34. putpixel(x,y,15);
35. }
36. }
37. else
38. printf("The point is outside the clipwindow \nThe point is clipped\n");
39. break;
40. case 2: exit(0);
41. }
42. getch();
43. }

Output:
Line Clipping:

It is performed by using the line clipping algorithm. The line clipping algorithms are:

1. Cohen Sutherland Line Clipping Algorithm


2. Midpoint Subdivision Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm:

In the algorithm, first of all, it is detected whether line lies inside the screen or it is
outside the screen. All lines come under any one of the following categories:

1. Visible
2. Not Visible
3. Clipping Case

1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within
the window. A line is visible and will be displayed as it is.

2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such
lines will not display. If any one of the following inequalities is satisfied, then the line
is considered invisible. Let A (x1,y2) and B (x2,y2) are endpoints of line.

xmin,xmax are coordinates of the window.

ymin,ymax are also coordinates of the window.


x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin

3. Clipping Case: If the line is neither visible case nor invisible case. It is considered
to be clipped case. First of all, the category of a line is found based on nine regions
given below. All nine regions are assigned codes. Each code is of 4 bits. If both
endpoints of the line have end bits zero, then the line is considered to be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle
window.

Following figure show lines of various types


Line AB is the visible case
Line OP is an invisible case
Line PQ is an invisible line
Line IJ are clipping candidates
Line MN are clipping candidate
Line CD are clipping candidate

Advantage of Cohen Sutherland Line Clipping:

1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.

Algorithm of Cohen Sutherland Line Clipping:

Step1:Calculate positions of both endpoints of the line

Step2:Perform OR operation on both of these end-points

Step3:If the OR operation gives 0000


Then
line is considered to be visible
else
Perform AND operation on both endpoints
If And ≠ 0000
then the line is invisible
else
And=0000
Line is considered the clipped case.

Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)

(a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window

(b) If bit 2 is "1" line intersect with right boundary


y3=y1+m(X-X1)
where X = Xwmax
where X more is maximum value of X co-ordinate of the window
(c) If bit 3 is "1" line intersects with bottom boundary
X3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window

(d) If bit 4 is "1" line intersects with the top boundary


X3=X1+(y-y1)/m
where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window

Example of Cohen-Sutherland Line Clipping Algorithm:

Let R be the rectangular window whose lower left-hand corner is at L (-3, 1) and
upper right-hand corner is at R (2, 6). Find the region codes for the endpoints in fig:

The region code for point (x, y) is set according to the scheme
Bit 1 = sign (y-ymax)=sign (y-6) Bit 3 = sign (x-xmax)= sign (x-2)
Bit 2 = sign (ymin-y)=sign(1-y) Bit 4 = sign (xmin-x)=sign(-3-x)

Here

So

A (-4, 2)→ 0001 F (1, 2)→ 0000


B (-1, 7) → 1000 G (1, -2) →0100
C (-1, 5)→ 0000 H (3, 3) → 0100
D (3, 8) → 1010 I (-4, 7) → 1001
E (-2, 3) → 0000 J (-2, 10) → 1000

We place the line segments in their appropriate categories by testing the region
codes found in the problem.

Category1 (visible): EF since the region code for both endpoints is 0000.
Category2 (not visible): IJ since (1001) AND (1000) =1000 (which is not 0000).

Category 3 (candidate for clipping): AB since (0001) AND (1000) = 0000, CD since
(0000) AND (1010) =0000, and GH. since (0100) AND (0010) =0000.

The candidates for clipping are AB, CD, and GH.

In clipping AB, the code for A is 0001. To push the 1 to 0, we clip against the
boundary line xmin=-3. The resulting intersection point is I1 (-3,3 ). We clip (do not
display) AI1 and I1 B. The code for I1is 1001. The clipping category for I1 B is 3 since
(0000) AND (1000) is (0000). Now B is outside the window (i.e., its code is 1000), so
we push the 1 to a 0 by clipping against the line ymax=6. The resulting intersection is
l2 (-1 ,6). Thus I2 B is clipped. The code for I2 is 0000. The remaining
segment I1 I2 is displayed since both endpoints lie in the window (i.e., their codes are
0000).

For clipping CD, we start with D since it is outside the window. Its code is 1010. We
push the first 1 to a 0 by clipping against the line ymax=6. The resulting intersection
I3 is ( ,6),and its code is 0000. Thus I3 D is clipped and the remaining
segment CI3 has both endpoints coded 0000 and so it is displayed.

For clipping GH, we can start with either G or H since both are outside the window.
The code for G is 0100, and we push the 1 to a 0 by clipping against the line
ymin=1.The resulting intersection point is I4 (2 ,1) and its code is 0010. We
clip GI4 and work on I4 H. Segment I4 H is not displaying since (0010) AND (0010)
=0010.

Program to perform Line Clipping using Cohen Sutherland Algorithm:

1. #include <iostream.h>
2. #include <conio.h>
3. #include <graphics.h>
4. #include <dos.h>
5. class data
6. {
7. int gd, gmode, x, y, xmin,ymin,ymax,xmax;
8. int a1,a2;
9. float x1, y1,x2,y2,x3,y3;
10. int xs, ys, xe, ye;
11. float maxx,maxy;
12. public:
13. void getdata ();
14. void find ();
15. void clip ();
16. void display (float, float,float,float);
17. void checkonof (int);
18. void showbit (int);
19. };
20. void data :: getdata ()
21. {
22. cout<<"Enter the minimum and maximum coordinate of window (x, y) ";
23. cin >>xmin>>ymin>>xmax>>ymax;
24. cout<<"Enter the end points of the line to be clipped";
25. cin >>xs>>ys>>xe>>ye;
26. display (xs, ys, xe,ye);
27. }
28. void data :: display (float, xs, float, ys,float xe, float ye)
29. {
30. int gd=DETECT;
31. initgraph (&gd,&gmode, "");
32. maxx=getmaxx();
33. maxy=getmaxy();
34. line (maxx/2,0,maxx/2,maxy);
35. line (0, maxy/2,maxx,maxy/2);
36. rectangle (maxx/2+xmin,maxy/2-ymax,maxx/2+xmax,maxy/2-ymin);
37. line (maxx/2+xs,maxy/2-ys,maxx/2+xe,maxy/2-ye);
38. getch();
39. }
40. void data :: find ()
41. {
42. a1=0;
43. a2=0;
44. if ((ys-ymax)>0)
45. a1+=8;
46. if ((ymin-ys)>0)
47. a1+=4;
48. if ((xs-xmax)>0)
49. a1+=2;
50. if ((xmin-xs)>0)
51. a1+=1;
52. if ((ye-ymax)>0)
53. a2+=8;
54. if ((ymin-ye)>0)
55. a2+=4;
56. if ((xe-xmax)>0)
57. a2+=2;
58. if ((xmin-xe)>0)
59. a2+=1;
60. cout<<"\nThe area code of Ist point is ";
61. showbit (a1);
62. getch ();
63. cout <<"\nThe area code of 2nd point is ";
64. showbit (a2);
65. getch ();
66. }
67. void data :: showbit (int n)
68. {
69. int i,k, and;
70. for (i=3;i>=0;i--)
71. {
72. and =1<<i;
73. k = n?
74. k ==0?cout<<"0": cout<<"1\"";
75. }
76. }
77. void data ::clip()
78. {
79. int j=a1&a2;
80. if (j==0)
81. {
82. cout<<"\nLine is perfect candidate for clipping";
83. if (a1==0)
84. {
85. else
86. {
87. checkonof(a1);
88. x2=x1;y2=y1;
89. }
90. if (a2=0)
91. {
92. x3=xe; y3=ye;
93. }
94. else
95. {
96. checkonof (a2);
97. x3=x1; y3=y1;
98. }
99. xs=x2; ys=y2;xe=x3;ye=y3;
100. cout << endl;
101. display (xs,ys,xe,ye);
102. cout<<"Line after clipping";
103. getch ()
104. }
105. else if ((a1==0) && (a2=0))
106. {
107. cout <<"\n Line is in the visible region";
108. getch ();
109. }
110. }
111. void data :: checkonof (int i)
112. {
113. int j, k,l,m;
114. 1=i&1;
115. x1=0;y1=0;
116. if (1==1)
117. {
118. x1=xmin;
119. y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys);
120. }
121. j=i&8;
122. if (j>0)
123. {
124. y1=ymax;
125. x1=xs+(y1-ys)/(ye-ys))*(xe-xs);
126. }
127. k=i & 4;
128. if (k==1)
129. {
130. y1=ymin;
131. x1=xs+((y1-ys)/(ye-ys))*(xe-xs);
132. }
133. m= i&2;
134. if (m==1)
135. {
136. x1=xmax;
137. y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys);
138. }
139. main ()
140. {
141. data s;
142. clrscr();
143. s.getdata();
144. s.find();
145. getch();
146. closegraph ();
147. return ();
148. }

Output:
Mid Point Subdivision Line Clipping Algorithm:

It is used for clipping line. The line is divided in two parts. Mid points of line is
obtained by dividing it in two short segments. Again division is done, by finding
midpoint. This process is continued until line of visible and invisible category is
obtained. Let (xi,yi) are midpoint

x5lie on point of intersection of boundary of window.

Advantage of midpoint subdivision Line Clipping:

It is suitable for machines in which multiplication and division operation is not


possible. Because it can be performed by introducing clipping divides in hardware.

Algorithm of midpoint subdivision Line Clipping:

Step1: Calculate the position of both endpoints of the line

Step2: Perform OR operation on both of these endpoints


Step3: If the OR operation gives 0000
then
Line is guaranteed to be visible
else
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=6000
then the line is clipped case.

Step4: For the line to be clipped. Find midpoint


Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.

Step5: Check each midpoint, whether it nearest to the boundary of a window or not.

Step6: If the line is totally visible or totally rejected not found then repeat step 1 to 5.

Step7: Stop algorithm.

Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-ordinates of A
(-4, 2) and B (-1, 7). Does this line visible. Find the visible portion of the line using
midpoint subdivision?

Solution:

Step1: Fix point A (-4, 2)

Step2: Find b"=mid of b'and b


So (-1, 5) is better than (2, 4)
Find b"&bb"(-1, 5) b (-1, 7)

So B""to B length of line will be clipped from upper side

Now considered left-hand side portion.

A and B""are now endpoints

Find mid of A and B""

A (-4, 2) B ""(-1, 6)
Liang-Barsky Line Clipping Algorithm:

Liang and Barsky have established an algorithm that uses floating-point arithmetic
but finds the appropriate endpoints with at most four computations. This algorithm
uses the parametric equations for a line and solves four inequalities to find the range
of the parameter for which the line is in the viewport.

Let P(x1, y1), Q(x2, y2) is the line which we want to study. The parametric equation
of the line segment from gives x-values and y-values for every point in terms of a
parameter that ranges from 0 to 1. The equations are

x=x1+(x2-x1 )*t=x1+dx*t and y=y1+(y2-y1 )*t=y1+dy*t


We can see that when t = 0, the point computed is P(x1, y1); and when t = 1, the
point computed is Q(x2, y2).

Algorithm of Liang-Barsky Line Clipping:

1. Set tmin=0 and tmax=1

2. Calculate the values tL,tR,tT and tB(tvalues).


If t<tmin or t<tmax? ignore it and go to the next edge
Otherwise classify the tvalue as entering or exiting value (using inner product to classify)
If t is entering value set tmin=t if t is exiting value set tmax=t.

3. If tmin< tmax? then draw a line from (x1 + dx*tmin, y1 + dy*tmin) to (x1 + dx*tmax?, y1 + dy*tmax? )

4. If the line crosses over the window, you will see (x1 + dx*tmin, y1 + dy*tmin) and (x1 + dx*tmax? , y1 + dy*tmax?) are
intersection between line and edge.

Text Clipping:

Several methods are available for clipping of text. Clipping method is dependent on
the method of generation used for characters. A simple method is completely
considered, or nothing considers method. This method is also called as all or none. If
all characters of the string are inside window, then we will keep the string, if a string
character is outside then whole string will be discarded in fig (a).

Another method is discarded those characters not completely inside the window. If a
character overlap boundary of window. Those will be discarded in fig (b).

In fig (c) individual character is treated. Character lies on boundary is discarded as


which it is outside the window.

Curve Clipping:

Curve Clipping involves complex procedures as compared to line clipping. Curve


clipping requires more processing than for object with linear boundaries. Consider
window which is rectangular in shape. The circle is to consider against rectangle
window. If circle is completely inside boundary of the window, it is considered visible.
So save the circle. If a circle is in outside window, discard it. If circle cut the
boundary then consider it to be clipping case.

Exterior Clipping:

It is opposite to previous clipping. Here picture which is outside the window is


considered. The picture inside the rectangle window is discarded. So part of the
picture outside the window is saved.

Uses of Exterior Clipping:

1. It is used for displaying properly the pictures which overlap each other.
2. It is used in the concept of overlapping windows.
3. It is used for designing various patterns of pictures.
4. It is used for advertising purposes.
5. It is suitable for publishing.
6. For designing and displaying of the number of maps and charts, it is also used.

Polygon Clipping:

Polygon clipping is applied to the polygons. The term polygon is used to define
objects having outline of solid. These objects should maintain property and shape of
polygon after clipping.

Polygon:

Polygon is a representation of the surface. It is primitive which is closed in nature. It


is formed using a collection of lines. It is also called as many-sided figure. The lines
combined to form polygon are called sides or edges. The lines are obtained by
combining two vertices.

Example of Polygon:

1. Triangle
2. Rectangle
3. Hexagon
4. Pentagon

Following figures shows some polygons.


Types of Polygons

1. Concave
2. Convex

A polygon is called convex of line joining any two interior points of the polygon lies
inside the polygon. A non-convex polygon is said to be concave. A concave polygon
has one interior angle greater than 180°. So that it can be clipped into similar
polygons.

A polygon can be positive or negative oriented. If we visit vertices and vertices visit
produces counterclockwise circuit, then orientation is said to be positive.
Sutherland-Hodgeman Polygon Clipping:

It is performed by processing the boundary of polygon against each window corner or


edge. First of all entire polygon is clipped against one edge, then resulting polygon is
considered, then the polygon is considered against the second edge, so on for all four
edges.

Four possible situations while processing

1. If the first vertex is an outside the window, the second vertex is inside the
window. Then second vertex is added to the output list. The point of
intersection of window boundary and polygon side (edge) is also added to the
output line.
2. If both vertexes are inside window boundary. Then only second vertex is added
to the output list.
3. If the first vertex is inside the window and second is an outside window. The
edge which intersects with window is added to output list.
4. If both vertices are the outside window, then nothing is added to output list.

Following figures shows original polygon and clipping of polygon against four
windows.
Disadvantage of Cohen Hodgmen Algorithm:

This method requires a considerable amount of memory. The first of all polygons are
stored in original form. Then clipping against left edge done and output is stored.
Then clipping against right edge done, then top edge. Finally, the bottom edge is
clipped. Results of all these operations are stored in memory. So wastage of memory
for storing intermediate polygons.

Weiler-Atherton Polygon Clipping:

When the clipped polygons have two or more separate sections, then it is the
concave polygon handled by this algorithm. The vertex-processing procedures for
window boundaries are modified so that concave polygon is displayed.

Let the clipping window be initially called clip polygon and the polygon to be clipped
the subject polygon. We start with an arbitrary vertex of the subject polygon and
trace around its border in the clockwise direction until an intersection with the clip
polygon is encountered:

1. If the edge enters the clip polygon, record the intersection point and continue to
trace the subject polygon.
2. If the edge leaves the clip polygon, record the intersection point and make a right
turn to follow the clip polygon in the same manner (i.e., treat the clip polygon as
subject polygon and the subject polygon as clip polygon and proceed as before).

Whenever our path of traversal forms a sub-polygon we output the sub-polygon as


part of the overall result. We then continue to trace the rest of the original subject
polygon from a recorded intersection point that marks the beginning of a not-yet
traced edge or portion of an edge. The algorithm terminates when the entire border
of the original subject polygon has been traced exactly once.

For example, the number in fig (a) indicates the order in which the edges and
portion of edges are traced. We begin at the starting vertex and continue along the
same edge (from 1 to 2) of the subject polygon as it enters the clip polygon. As we
move along the edge that is leaving the clip polygon, we make a right turn (from 4 to
5) onto the clip polygon, which is now considered the subject polygon. Following the
same logic leads to the next right turn (from 5 to 6) onto the current clip polygon,
this is the original subject polygon. With the next step done (from 7 to 8) in the same
way, we have a sub-polygon for output in fig (b). We then resume our traversal of the
original subject polygon from the recorded intersection point where we first changed
our course. Going from 9 to 10 to 11 produces no output. After skipping the already
traversed 6 and 7, we continue with 12 and 13 and come to an end. The fig (b) is the
final result.

Pointing and Positioning Techniques

Pointing technique refers to look at the items already on the screen whereas the
positioning technique refers to position the item on the screen to a new position, i.e.,
the old current position. The user indicates a position on the screen with an input
device, and this position is used to insert a symbol.

There are various pointing and positioning devices which are discussed below:

1. Light Pen
2. Mouse
3. Tablet
4. Joystick
5. Trackball and spaceball

1. Light Pen: It is a pointing device. When light pen is pointed at an item on the
screen, it generates information from which the item can be identified by the
program. It does not have any associated tracking hardware instead tracking is
performed by software, making use of the output function of the display. All light
pen programs depend on a rapid response from the pen when it is pointed at the
screen fast response light pens can be build by using a highly sensitive photocell
such as a photomultiplier tube.

2. Mouse: It is a positioning device which consists of a small plastic box resting on


two metal wheels whose axes are at right angles. Each wheel of the mouse is linked
to a shaft encoder that delivers an electrical pulse for every incremental rotation of
the wheel. As the mouse is rolled around on a flat surface, its movement in two
orthogonal directions is translated into rotation of the wheels. These rotations can be
measured by counting the pulses received from the shaft encoders. The connected
values may be held in registers accessible to the computer on written directly into
the computer memory. It is simple and low cost, and there is no need to pick it up to
use it. The mouse sits on the table surface. But the mouse cannot be used for
tracing data from paper since a small rotation of the mouse will cause an error in all
the reading and it is complicated handprint character for recognition by the
computer.

3. Tablet: It is also a positioning device and is used to describe a flat surface


separate from the display, on which the user draws with a stylus. There are two
types of tablets:

1. Acoustic Tablet: It depends on the use of strip microphones which are


mounted along two adjacent edges of the tablet. The styles have a small piece
of ceramic mounted close to its tip, and at regular intervals, a small spark is
generated across the surface of the ceramic between two electrodes. The
microphones pick up the pulse of sound produced by the spark and two
counters record the delay between creating the spark and receiving the sound.
These two delays are proportional to the stylus distance from the two edges of
the tablet where the microphones are mounted.
2. Electro-acoustic Tablet: In this technique, the writing surface is a sheet of
magnetostrictive material acting as a row of delay lines. An electric pulse
travels through the sheet first horizontally and then vertically and is detected
by a sensor in the stylus. A counter is used to determine the delay from the
time the pulse is issued to the time it is detected; from this value, the position
of the stylus can be determined. The electro-acoustic tablet is quieter in
operation than its acoustic counterpart and is less affected by noise or air
movement.

4. Joystick: A joystick consists of a small that is used to steer the screen cursor
around. The distance that the stick is moved in any direction from its center position
corresponds to the screen-cursor movement in that direction. Pressure sensitive
joysticks have a non-moveable stick. Pressure on the stick is measured with strain
gauges and converted to the movement of the cursor in the direction specified.

5. Trackball and spaceball: Trackball is a ball that can be rotated with the fingers
to produces screen-cursor movement potentiometers, attached to the ball, measure
the amount and direction of rotation. Trackballs are after mounted on keyboards,
whereas space-ball provides six degrees of freedom. Spaceballs is used for three-
dimensional positioning and selection operation in virtual reality system, modeling,
animation, CAD and other applications.

Elastic or Rubber Band Techniques

Rubber banding is a popular technique of drawing geometric primitives such as line,


polylines, rectangle, circle and ellipse on the computer screen.

It becomes an integral part and de facto standard with the graphical user interface
(GUI) for drawing and is almost universally accepted by all windows based
applications.

The user specifies the line in the usual way by positioning its two endpoints. As we
move from the first endpoint to the second, the program displays a line from the first
endpoint to the cursor position, thus he can see the lie of the line before he finishes
positioning it.

The effect is of an elastic line stretched between the first endpoint and the cursor;
hence the name for these techniques.

Consider the different linear structures in fig (a) and fig (d), depending on the
position of the cross-hair cursor. The user may move the cursor to generate more
possibilities and select the one which suits him for a specific application.
Selection of Terminal Point of the Line:

The user moves the cursor to the appropriate position and selects.

Then, as the cursor is moved, the line changes taking the latest positions of the
cursors as the end-point.

As long as the button is held down, the state of the rubber band is active.

The process is explained with the state transition diagram of rubber banding in fig:

When the user is happy with the final position, the pressed button is released, and
the line is drawn between the start and the last position of the cursor.

Example: This is widely followed in MS-Window based Applications like in the case
of a paintbrush drawing package.

Other geometric entities can be drawn in a rubber-band fashion:

- Horizontally or vertically constructed lines

- Rectangles

- Arcs of circles

This technique is very helpful in drawing relatively complex entities such as


rectangles and arcs.

Advantage:

1. It is used for drawing all geometric entities such as line, polygon, circle,
rectangle, ellipse, and other curves.
2. It is easy to understand and implement.

Disadvantage:

1. It requires computational resources like software and CPU speed.


2. Expensive

Dragging

Dragging is used to move an object from one position to another position on the
computer screen. To drag any other object, first, we have to select the object that we
want to move on the screen by holding the mouse button down. As cursor moved on
the screen, the object is also moved with the cursor position. When the cursor
reached the desired position, the button is released.

The following diagram represents the dragging procedure:

Animation

Animation refers to the movement on the screen of the display device created by
displaying a sequence of still images. Animation is the technique of designing,
drawing, making layouts and preparation of photographic series which are
integrated into the multimedia and gaming products. Animation connects the
exploitation and management of still images to generate the illusion of movement. A
person who creates animations is called animator. He/she use various computer
technologies to capture the pictures and then to animate these in the desired
sequence.

Animation includes all the visual changes on the screen of display devices. These are:

1. Change of shape as shown in fig:


2. Change in size as shown in fig:

3. Change in color as shown in fig:

4. Change in structure as shown in fig:

5. Change in angle as shown in fig:


Application Areas of Animation

1. Education and Training: Animation is used in school, colleges and training


centers for education purpose. Flight simulators for aircraft are also animation
based.

2. Entertainment: Animation methods are now commonly used in making motion


pictures, music videos and television shows, etc.

3. Computer Aided Design (CAD): One of the best applications of computer


animation is Computer Aided Design and is generally referred to as CAD. One of the
earlier applications of CAD was automobile designing. But now almost all types of
designing are done by using CAD application, and without animation, all these work
can't be possible.

4. Advertising: This is one of the significant applications of computer animation.


The most important advantage of an animated advertisement is that it takes very
less space and capture people attention.

5. Presentation: Animated Presentation is the most effective way to represent an


idea. It is used to describe financial, statistical, mathematical, scientific & economic
data.

Animation Functions

1. Morphing: Morphing is an animation function which is used to transform object


shape from one form to another is called Morphing. It is one of the most complicated
transformations. This function is commonly used in movies, cartoons, advertisement,
and computer games.

The process of Morphing involves three steps:


1. In the first step, one initial image and other final image are added to morphing
application as shown in fig: Ist & 4th object consider as key frames.
2. The second step involves the selection of key points on both the images for a
smooth transition between two images as shown in 2nd object.

3. In the third step, the key point of the first image transforms to a corresponding
key point of the second image as shown in 3rd object of the figure.

2. Wrapping: Wrapping function is similar to morphing function. It distorts only the


initial images so that it matches with final images and no fade occurs in this
function.

3. Tweening: Tweening is the short form of 'inbetweening.' Tweening is the process


of generating intermediate frames between the initial & last final images. This
function is popular in the film industry.

4. Panning: Usually Panning refers to rotation of the camera in horizontal Plane. In


computer graphics, Panning relates to the movement of fixed size window across the
window object in a scene. In which direction the fixed sized window moves, the
object appears to move in the opposite direction as shown in fig:
If the window moves in a backward direction, then the object appear to move in the
forward direction and the window moves in forward direction then the object appear
to move in a backward direction.

5. Zooming: In zooming, the window is fixed an object and change its size, the object
also appear to change in size. When the window is made smaller about a fixed center,
the object comes inside the window appear more enlarged. This feature is known
as Zooming In.

When we increase the size of the window about the fixed center, the object comes
inside the window appear small. This feature is known as Zooming Out.

6. Fractals: Fractal Function is used to generate a complex picture by using


Iteration. Iteration means the repetition of a single formula again & again with
slightly different value based on the previous iteration result. These results are
displayed on the screen in the form of the display picture.

You might also like