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 |
|
|
Pre-requisite |
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(x0,y0) 2.Load ( x0,y0 ) 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: p0 = 2 ∆y – ∆x 4.At each xk, the next point the line , starting at k=0, perform the following test: If pk < 0 , the next point to plot is (xk + 1 ,yk ) and pk+1 = pk + 2 ∆y Otherwise ,the next point to plot is (xk + 1, yk +1) and pk+1 = pk + 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 |
|
|
Pre-requisite |
Knowledge of |
|
Algorithm |
Midpoint circle algorithm
|
|
Sample Output |
Enter the coordinates of the centre :- x-coordiante = 350 y-coordinate = 250
Enter the radius :- 50
|
|
Post Lab Assignment |
|
|
Lab Assignment 3 |
|
|
Title |
Ellipse Drawing Algorithms |
|
Objective |
To study and Implement Midpoint Ellipse Algorithm |
|
References |
|
|
Pre-requisite |
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 |
|
|
Pre-requisite |
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. X-intersect = x1 and y = y1 then apply vertex test to check whether to consider one intersect or two intersects. Store all x-intersect in the x-intersect [ ] array 10. Store x-intersect [ ] array in the ascending order 11. Extract pairs of intersects from the sorted x-intersect [ ] 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 >= ymax 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 |
|
|
Pre-requisite |
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 Sx and SY 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 tx and tY 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 co-ordinates of vertex 1 :- 30 30 Enter the co-ordinates of vertex 2 :- 30 90 Enter the co-ordinates of vertex 3 :- 90 90 Enter the co-ordinates of vertex 4 :- 90 30 Enter the Translation factor for x and y :-20 20
|
|
Post Lab Assignment |
|
|
|
|
|
Title |
Composite Transformations |
|
Objective |
|
|
References |
|
|
Pre-requisite |
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 X-direction shear relative to the x axis is produced by the transformation matrix
A y-direction 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 co-ordinates :- 30 30 Enter the x and y co-ordinates :- 30 90 Enter the x and y co-ordinates :- 90 90 Enter the x and y co-ordinates :- 90 30
2.Reflection along Y-axis 3.Exit
Enter your choice.......1
2.Reflection along Y-axis 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 |
|
|
Pre-requisite |
Knowledge of
|
|
Algorithm
|
Cohen sutherland Line Clipping Algorithm
Liang Barsky Line Clipping Algorithm
p2 = ∆x q2 = xwmax - x 1 q1 = - ∆y q3 = y1 - ywmin
q2 = ∆y
q4 = ywmax - y1
|
|
|
|
|
Sample Output |
Menu 1.Cohen Sutherland Line Clipping Algorithm 2.Liang Barsky Line Clipping Algorithm 3.Exit Enter your choice.......1 Enter Minimum window co-ordinates :- 200 250 Enter Maximum window co-ordinates :- 300 350 Enter co-ordinates of first point of line :- 180 250 Enter co-ordinates 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 co-ordinates :- 200 250 Enter Maximum window co-ordinates :- 300 350 Enter co-ordinates of first point of line :- 180 250 Enter co-ordinates 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 |
|
|
Pre-requisite |
Knowledge of
|
|
Algorithm |
Sutherland Hodgman Algorithm
|
|
Sample Output |
Menu 1.Sutherland Hodgman Polygon Clipping Algorithm 2.Exit Enter your choice.......1 Enter Minimum window co-ordinates :- 200 250 Enter Maximum window co-ordinates :- 300 350 Enter co-ordinates of first point of line :- 180 250 Enter co-ordinates 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 B-Splines |
|
References |
|
|
Pre-requisite |
Knowledge of
|
|
Algorithm |
Bezeir Curves
|
|
Sample Output |
Menu 1.Curves Generation using Bezeir Curves 2.Curves Generation using B-Splines 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
p1 p3
Menu 1.Curves Generation using Bezier Curves 2.Curves Generation using B-Splines 3.Exit Enter your choice.......2
p1 p3
1.Curves Generation using Bezier Curves 2.Curves Generation using B-Splines 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 |
|
|
Pre-requisite |
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 |
|