Computer Graphics
Lab Manual
Computer Graphics
T.E. Computer
(Sem VI)
Index
Sr. No. 
Title of Programming Assignments 
Page No. 


Line Drawing Algorithms 
3 

Circle Drawing Algorithms 
6 

Ellipse Drawing Algorithms 
8 

Polygon Filling Algorithms 
10 

Basic Transformations 
13 

Composite Transformations 
17 

Line Clipping Algorithms 
21 

Polygon Clipping Algorithms 
26 

Curve Generations 
28 

Animation Program 
31 
Note :
All assignments require the knowledge of Graphics functions in C/C++.
Proper
header files have to be used for the initialization of graphics
functions
Lab Assignment 1 

Title 
Line Drawing Algorithms 
Objective 
1.To study and Implement DDA Algorithm 2.To study and Implement Bresenham 's Algorithm 
References 

Prerequisite 
Knowledge of

Algorithm 
DDA algorithm:
Input to the function is two endpoints (x1,y1) and (x2,y2)
Bresenham's Line Drawing Algorithm:
1. Input the two line endpoints and store the left endpoint in(x_{0},y_{0}) 2.Load ( x_{0},y_{0 }) into the frame buffer; that is , plot the first point. 3.Calculate constants ∆x, ∆y,2 ∆y and 2 ∆y 2 ∆x , and obtain the starting value for the decision parameter as: p_{0} = 2 ∆y – ∆x 4.At each x_{k}, the next point the line , starting at k=0, perform the following test: If p_{k }< 0 , the next point to plot is (x_{k} + 1 ,y_{k} ) and p_{k}+1 = p_{k} + 2 ∆y Otherwise ,the next point to plot is (x_{k} + 1, y_{k} +1) and pk+1 = p_{k} + 2 ∆y – 2 ∆x 5.Repeat step 4 ∆x times. 
Sample Output 
Enter the option that you want 1.DDA Algorithm 2.Bresenham Algorithm 3.Exit
1 Enter a Initial Point : 100 200 Enter the Final Point: 200 300
1.DDA Algorithm 2.Bresenham Algorithm 3.Exit
2 Enter a Initial Point : 100 200 Enter the Final Point: 200 300
Enter the option that you want 1.DDA Algorithm 2.Bresenham Algorithm 3.Exit

Post Lab Assignment 

Lab Assignment 2 

Title 
Circle Drawing Algorithm 
Objective 
To study and Implement Midpoint circle algorithm given the points of the centre and the radius. 
References 

Prerequisite 
Knowledge of 
Algorithm 
Midpoint circle algorithm

Sample Output 
Enter the coordinates of the centre : xcoordiante = 350 ycoordinate = 250
Enter the radius : 50

Post Lab Assignment 

Lab Assignment 3 

Title 
Ellipse Drawing Algorithms 
Objective 
To study and Implement Midpoint Ellipse Algorithm 
References 

Prerequisite 
Knowledge of

Algorithm 
Midpoint Ellipse algorithm

Sample Output 
Enter the option that you want 1.Midpoint Ellipse Algorithm 2.Exit
1 Enter the coordinates of the center : 100 200 Enter the Minor axis : 50 Enter the Major axis : 100
Enter the option that you want 1.Midpoint Ellipse Algorithm 2.Exit 2

Post Lab Assignment 

Lab Assignment 4 

Title 
Polygon Filling Algorithms 
Objective 

References 

Prerequisite 
Knowledge of 
Algorithm 
(x,y) are the interior points, boundary is the boundary color and fill_color is the color to be filled. Following is a recursive method for boundary fill.


9. VertexxIf x intersects is vertex i.e. Xintersect = x_{1 } and y = y_{1 }then apply vertex test to check whether to consider one intersect or two intersects. Store all xintersect in the xintersect [ ] array 10. Store xintersect [ ] array in the ascending order 11. Extract pairs of intersects from the sorted xintersect [ ] array 12. Pass pair of x values to line drawing routine to draw corresponding line segments 13. Set y = y 1 14. Repeat steps 7 through 13 until y >= y_{max} 15. Stop.

Sample Output 
Enter your choice 1.Boundary Fill 2.Scan line polygon fillling algorithm. 3.Exit
Enter Choice.......1
1.Boundary Fill 2.Scan line polygon fillling algorithm. 3.Exit
Enter Choice.......2
1.Boundary Fill 2.Scan line polygon fillling algorithm. 3.Exit
Enter Choice.......3

Post Lab Assignment 

Lab Assignment 5 

Title 
Basic Transformations 
Objective 
To Implement set of Basic Transformations on Polygon i.e Translation , Rotation and Scaling 
References 

Prerequisite 
Knowledge of 
Description 
Transformations allows us to uniformly alter the entire picture. The geometric transformations considered here – translation, scaling and rotation are expressed in terms of matrix multiplication. Homogeneous coordiantes are considered to uniformly treat the translations.
A 2D point can be scaled by multiplication of the coordiante values (x,y) by scaling factors S_{x }and S_{Y }to produce the transformed coordinates (x',y').
= _{ }
Translation Transformations: A 2D point can be translated by adding the coordiante values (x,y) by Translation distances t_{x }and t_{Y }to produce the transformed coordinates (x',y'). Matrix format: =
A 2D point can be rotated by repositioning it along a circular path in the xy plane. We specify the rotation angle and the position of the rotation point about which the object is to be rotated. Multiplication of the coordiante values (x,y) by rotation matrix produce the transformed coordinates (x',y'). Matrix format: =

Sample Output 
Enter your choice 1.Translation
4.Exit
Enter the no. of edges :4 Enter the coordinates of vertex 1 : 30 30 Enter the coordinates of vertex 2 : 30 90 Enter the coordinates of vertex 3 : 90 90 Enter the coordinates of vertex 4 : 90 30 Enter the Translation factor for x and y :20 20

Post Lab Assignment 



Title 
Composite Transformations 
Objective 

References 

Prerequisite 
Knowledge of

Description 
Reflection Reflection is a transformation that produces a mirror image of an object. Transformation matrix for reflection about the line y=0, is


Shearing: shearing is a transformation that distorts the shape of an object. An Xdirection shear relative to the x axis is produced by the transformation matrix
A ydirection shear relative to other referencelines is produced by the transformation matrix
Rotation about an arbitrary point This is done by three transformation steps: translation of the arbitrary point (xc,yc) to the origin, rotate about the origin, and then translate the center of rotation back to where it belongs. To tranform a point, we would multiply all the transformation matrices together to form an overall transformation matrix.
=

Output 
1.Reflection 2.Shearing 3.Rotation about an arbitrary point.
Enter your choice.......1
Enter the no. of edges :4 Enter the x and y coordinates : 30 30 Enter the x and y coordinates : 30 90 Enter the x and y coordinates : 90 90 Enter the x and y coordinates : 90 30
2.Reflection along Yaxis 3.Exit
Enter your choice.......1
2.Reflection along Yaxis 3.Exit Enter your choice.......2


1.Reflection 2.Shearing 3.Exit Enter your choice.......2 Shear Factor > X and Y directions : 2 1

Post Lab Assignment 

Lab Assignment 7 

Title 
Line Clipping Algorithm 
Objective 
1.To study and Implement Line Clipping Algorithm using Cohen Sutherland 2.To study and Implement Line Clipping Algorithm using Liang Barsky 
References 

Prerequisite 
Knowledge of

Algorithm

Cohen sutherland Line Clipping Algorithm
Liang Barsky Line Clipping Algorithm
p_{2 } = ∆x_{ } q_{2 } = x_{wmax}  x_{ 1} q_{1 }=  ∆y_{ }q_{3 } = y_{1 }  y_{wmin } q_{2 }= ∆y_{ } q_{4 }= y_{wmax } y_{1 }


_{ } 
Sample Output 
Menu 1.Cohen Sutherland Line Clipping Algorithm 2.Liang Barsky Line Clipping Algorithm 3.Exit Enter your choice.......1 Enter Minimum window coordinates : 200 250 Enter Maximum window coordinates : 300 350 Enter coordinates of first point of line : 180 250 Enter coordinates of second point of line : 200 300
Menu 1.Cohen sutherland Line Clipping Algorithm 2.Liang Barsky Line Clipping Algorithm 3.Exit
Enter Minimum window coordinates : 200 250 Enter Maximum window coordinates : 300 350 Enter coordinates of first point of line : 180 250 Enter coordinates of second point of line : 200 300
1.Cohen sutherland Line Clipping Algorithm 2.Liang Barsky Line Clipping Algorithm 3.Exit Enter your choice.......3 
Post Lab Assignment 

Lab Assignment 8 

Title 
Polygon Clipping Algorithm 
Objective 

References 

Prerequisite 
Knowledge of

Algorithm 
Sutherland Hodgman Algorithm

Sample Output 
Menu 1.Sutherland Hodgman Polygon Clipping Algorithm 2.Exit Enter your choice.......1 Enter Minimum window coordinates : 200 250 Enter Maximum window coordinates : 300 350 Enter coordinates of first point of line : 180 250 Enter coordinates of second point of line : 200 300
A
Menu 1.Sutherland Hodgman Polygon Clipping Algorithm 2.Exit Enter your choice.......2

Post Lab Assignment 

Lab Assignment 9 

Title 
Curves Generation 
Objective 
1.To study and Implement Curves Generation using Bezeir Curves 2.To study and Implement Curves Generation using BSplines 
References 

Prerequisite 
Knowledge of

Algorithm 
Bezeir Curves

Sample Output 
Menu 1.Curves Generation using Bezeir Curves 2.Curves Generation using BSplines 3.Exit
Enter your choice.......1
Enter the no. of control points : 4 Enter the control point1 : 20 50 Enter the control point2 : 30 10 Enter the control point3 : 40 50 Enter the control point4 : 50 10
p2 P4
p1 p3
Menu 1.Curves Generation using Bezier Curves 2.Curves Generation using BSplines 3.Exit Enter your choice.......2 p2 P4
p1 p3
1.Curves Generation using Bezier Curves 2.Curves Generation using BSplines 3.Exit
Enter your
choice.......3

Post Lab Assignment 

Lab Assignment 10 

Title 
Animation Program. 
Objective 
To Implement a program with animation of objects (segments) obtained by scan conversion. 
References 

Prerequisite 
Knowledge of

Description 
Animation: Sequences of pictures at educate or explain may require images of 3D objects. Although animation uses graphics as much for art as for realism, it depends heavily on motions to substitute for realism of an individual image. Animation is done by photographing a sequence of drawings, each slightly different from the previous. This can be achieved by segmentation. 
Conclusion 
For eg., to show a person moving his arm, a series of drawings is photographed, each drawing showing the arm at a different position. When the images are displayed one after another from the frame buffer, we perceive the arm as moving through the sequence. 
Post Lab Assignment 
