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

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • Point Plotting Methods

  • Graphics Initializations

  • DDA Algorithm

  • Bresenham 's Algorithm.

Algorithm

DDA algorithm:


Input to the function is two endpoints (x1,y1) and (x2,y2)

  1. length abs(x2-x1);

  2. if (abs(y2-y1) > length) then length abs(y2-y1);

  3. xincrement (x2-x1) / length;

  4. yincrement (y2-y1) / length;

  5. x ←x + 0.5; y ← Y + 0.5;

  6. for i ← 1 to length follow steps 7 to 9

  7. plot (trunc(x),trunc(y));

  8. x ← x + xincrement ;

  9. y y + yincrement ;

  10. stop.



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






Enter the option that you want

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

  1. What are the advantages of Bresenhams algorithm over DDA algorithm.

  2. How can the Bresenham's algorithm be modified to accommodate all types of lines?

  3. Modify the algorithms by implementing antialiasing procedures also.

  4. Modify the BRESENHAM algorithm so that it will produce a dashed-line pattern. Dash length should be independent of slope.





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

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

    Knowledge of

  • Midpoint circle algorithm

Algorithm

    Midpoint circle algorithm


  1. Input radius r and circle center (x0,y0), and obtain the first point on the circumference of a circle centered on the origin as
    (x0,y0) = (0 , r)

  2. Calculate the initial value of the decision parameter as
    p0 = 5 / 4 – r

  3. At each xk position , starting at k=0, perform the following test:
    If pk < 0 , the next point along the circle centered on (0,0) is (xk + 1 ,yk ) and pk+1 = pk + 2 xk+1 + 1
    Otherwise ,the next point along the circle is (xk + 1, yk -1) and
    pk+1 = pk + 2 xk+1 + 1 - 2yk+1
    Where 2 xk+1 = 2xk + 2 and 2yk+1 = 2 yk- 2.

  1. Determine symmetry points in the other seven octants

  1. Move each calculated pixel position (x,y) onto the circular path centered on (x0,y0) and plot the coordinate values:

    x = x + xc y = y + yc

  2. Repeat step 3 through 5 until x>= y



Sample Output

Enter the coordinates of the centre :-

x-coordiante = 350

y-coordinate = 250


Enter the radius :-

50







Post Lab Assignment

  1. Outline a method to for antialiasing a circle boundary. How would this method be modified to antialias elliptical boundaries.

  2. Revise the midpoint circle algorithm to display a circle so that the geometric standards are maintained.


Lab Assignment 3

Title

Ellipse Drawing Algorithms

Objective

To study and Implement Midpoint Ellipse Algorithm

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • Midpoint Ellipse Algorithm

Algorithm

    Midpoint Ellipse algorithm

  1. 1.Input rx',ry' and ellipse center (xc',yc), and obtain the first point on the ellipse centered on the origin as
    (x0,y0) = (0 , ry)

  2. Calculate the initial value of the decision parameter in region 1 as p10 = r2y - r2xry + 1 / 4 r2x

  3. At each xk position in region 1 , starting at k=0, perform the following test:
    If p1k < 0 ,the next point along the ellipse centered on (0,0) is (xk + 1 ,yk ) and
    p1k+1 = p1k + 2 r2y xk+1 + r2y
    Otherwise ,the next point along the circle is (xk + 1, yk -1) and
    p1k+1 = p1k + 2 r2y xk+1 - 2r2x yk+1 + r2y
    With
    2 r2y xk+1 = 2 r2y xk + 2r2y' 2 r2x yk+1 = 2 r2x yk - 2 r2x

  4. Calculate the initial value of the decision parameter in region 2 using the last point (x0,y0) calculated in the region 1 as
    p20 p1k+1 = r2y ( x0 + 1 / 2 )2+ r2x ( y0 - 1 )2 - r2x r2y

  5. At each xk position in region 2 , starting at k=0, perform the following test:
    If p2k > 0 ,the next point along the ellipse centered on (0,0) is (xk ,yk -1) and
    p2k+1 = p2k + 2 r2y yk+1 + r2x
    Otherwise ,the next point along the circle is (xk + 1, yk -1) and
    p2k+1 = p2k + 2 r2y xk+1 - 2r2x yk+1 + r2x
    using the same incremental calculations for x and y as in region 1

  6. Determine symmetry points in the other three quadrants

  7. Move each calculated pixel position (x,y) onto the elliptical path centered on (xc',yc) and plot the coordinate values:

    x = x + xc' y = y + yc

  8. Repeat steps for region1 until 2 r2y x >= 2r2x y



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

  1. Write a procedure to scan the interior of a specified ellipse into a solid color.

  2. Outline a method for antialiasing a ellipse boundary.





Lab Assignment 4

Title

Polygon Filling Algorithms

Objective

  1. To study and Implement Polygon Filling Algorithms

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

    Knowledge of

  • Polygon Filling Algorithms

        • Boundary Fill Algorithm(4 connected and 8 connected)

        • Scan line polygon fillling Algorithm.

Algorithm

        • Boundary Fill 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.


        1. present_color = getcolor() // a function which returns the current color of (x,y)

        2. if present_color <> boundary and
          if present_color <> fill_color then repeat steps 3-7

        3. set_pixel (x,y, fill_color)

        4. call the algorithm recursively for points (x + 1, y)

        5. call the algorithm recursively for points (x – 1,y)

        6. call the algorithm recursively for points (x,y + 1)

        7. call the algorithm recursively for points (x,y - 1)

        8. stop


        • Scan line polygon fillling algorithm.

        1. Input n, number of vertices of polygon

        2. input x and y coordinated of all vertices i array x[n] and y[n]

        3. find ymin and yma x

        4. Store the initail x values(x1) y values y1 and y2 for two endpoints and x increment x from scan line to scan line for each edge in the array edges [n] [4] while doing this check that y1 > y2 , if not interchange y1 and y2 and corresponding x1 and x2 so that for each edge , y1 represents its maximum y coordinate and y2 represents it minimum y coordiante

        5. Sort the rows of array , edges [n] [4] in descending order of y1 ,descending order of y2 and ascending order of x2

        6. Set y = yma x

        7. Find the active edges and update active edge list:

          if( y > y2 and y<= y1 ) then edge is active
          Otherwise edge is not active

        8. Compute the x intersects for all active edges for current y values [ initially x-intersect is and x intersects for successive y values can be given as
          xi+1 = x i + x

          Where x = - 1/m
          and m= y2 - y1 / x2 - x1

          i.e slope of a line segment


                                  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




Enter your choice

1.Boundary Fill

2.Scan line polygon fillling algorithm.

3.Exit


Enter Choice.......2




Enter your choice

1.Boundary Fill

2.Scan line polygon fillling algorithm.

3.Exit


Enter Choice.......3



Post Lab Assignment

  1. Modify the 4-connected boundary fill algorithm to avoid excess stacking.

  2. Develop the flood fill algorithm to fill any interior of any specified area.

  3. What is pattern filling? Where it is used? What are the constraints involved?






Lab Assignment 5

Title

Basic Transformations

Objective

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

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

    Knowledge of


  • Basic Transformations on Polygon

    • Translation

    • Rotation

    • Scaling


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.


Scaling Transformations:

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').


Matrix format:

=


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:

=


Rotation Transformations:

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

  1. Rotation

  2. Scaling

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

  1. What is the significance of homogeneous co-ordinates? Give the homogeneous co-ordinates fot the basic transformations.

  2. Why are matrices used for implementing transformations.








Lab Assignment 6

Title

Composite Transformations

Objective

  1. To study and Implement set of Composite Transformations on Polygon i.e Reflection, Shear (x &Y), rotation about an arbitrary point.

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • Composite Transformations on Polygon

    • Reflection

    • Shear

    • Rotation about an arbitrary point.


Description

Reflection

Reflection is a transformation that produces a mirror image of an object.

Transformation matrix for reflection about the line y=0, is


Transformation matrix for reflection about the line x=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.

  1. The translation which moves (xc,yc) to the origin:

  2. the rotation is

=

  1. and the translation to move the center point back is



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







1.Reflection along X-axis

2.Reflection along Y-axis

3.Exit


Enter your choice.......1







1.Reflection along X-axis

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

  1. Show that two successive reflections about any line passing through the coordinate origin is equivalent to single rotation about the origin.

  2. Determine the sequence of basic transformations that are equivalent to the x-direction and y-direction shearing matrix.

  3. Show that transformation matrix for a reflection about the line y=x, is equivalent to a reflection relative to the x axis followed by a counterclockwise rotation of 90 degrees.








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

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • Line Clipping Algorithms using

    • Cohen Sutherland

    • Liang Barsky

Algorithm






















































Cohen sutherland Line Clipping Algorithm

  1. Input two endpoints of the line say p1 ( x 1 , y1 ) and p2 ( x 2 , y 2 )

  2. Input two corners (Let-top and right -bottom ) of the window , say ( wx1 ,wy1 pk and wx 2 , wy 2)

  3. Assign the region codes for two endpoints p1 and p2 using following steps :
    Initialize code with bits 0000

    Set Bit1 – if (x < wx1 )
    Set Bit2 – if (x < wx2 )
    Set Bit3 – if (y < wy2 )
    Set Bit4 – if (y < wy1 )

  4. Check for visibility of line

  1. If region codes for both endpoints p1 and p2 are zero then the line is completely visible. Hence draw the line and go to step 9

  2. If region codes for both endpoints are not zero and the logicall ANDing of them is also nonzero then the line is completely invisible. So reject the line and go to 9

  3. If region codes for two endpoints do not satisfy the conditionin (4a and 4b the line is partiallly visible.

  1. Determine the intersecting edge of the clipping window by inspecting the region codes of two endpoints

  1. If region codes for both endpoints are non- zero,find intersecting point p'1 and p'2 with boundary edges of clipping window with respect to point p1 and point p2 respectively

  2. If region codes for any one endpoints are non-zero,find intersecting point p'1 or p'2 with boundary edges of clipping window with respect to it.

  1. Divide the Line segments considering intersection points

  2. Reject the line segments if any one endpoint of it appears outsides the clipping window

  3. Draw the remaining line segments

  4. Stop



Liang Barsky Line Clipping Algorithm


  1. 1.Input two endpoints of the line say p1 ( x 1 , y1 ) and p2 ( x 2 , y 2 )

  2. 2.Input two corners (Let-top and right -bottom ) of the window , say ( xwmin ,ywmax , xwmax , ywmin)

  3. Calculate the values of the parameter pi and qj for i = 1,2,3,4 such that
        p1 = - x q1 = x 1 - xwmin

              p2 = x q2 = xwmax - x 1

              q1 = - y q3 = y1 - ywmin

              q2 = y q4 = ywmax - y1

  1. If pi = 0 then
    The line is parallel to ith boundary
    Now, if qi < 0 then
    Line is completely outside the boundary ,hence discard the line segment and goto stop
    Otherwise, check whether the line is horizontal or vertical and accordingly check the line endpoint with corresponding boundaries. If line endpoint within the bounded area then use them to draw line otherwise use boundary coordinates to draw line. Go to stop

  2. Initialise values for t1 and t2 as
    t1 = 0 and t2 =1

  3. Calculate values for qi / pi for i = 1,2,3,4

  4. Select values of qi / pi where pi < 0 and assign maximum out of them as t1
  5. Select values of qi / pi where pi < 0 and assign minimum out of them as t2
  6. If ( t1 < t2 )
    Calculate the endpoints of the clipped lines as follows:-
    xx 1 = x 1 + t1x
    xx2 = x 1 + t2 x
    yy1 = y1 + t1 y
    yy2 = y1 + t2 y
    Draw line ( xx 1 , xx2 , yy1 , yy2 )

  7. Stop


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 your choice.......2

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 your choice.......3

Post Lab Assignment

  1. Modify the Liang-Barsky line clipping algorithm to polygon clipping.

  2. Write a routine to clip an ellipse against a rectangular window.

  3. Write a routine to implement exterior clipping on any part of a defined picture using any specified window.





Lab Assignment 8

Title

Polygon Clipping Algorithm

Objective

  1. To study and Implement Polygon Clipping Algorithm using sutherland Hodgman Algorithm

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • Polygon Clipping Algorithm

    • Sutherland Hodgman Algorithm

Algorithm

Sutherland Hodgman Algorithm

  1. Input Coordinates of all vertices of the polygon

  2. Input coordiantes of the clipping window

  3. Consider the left edge of the window

  4. Compare the vertices of each edge of the polygon , individually with the clipping plane

  5. Save the resulting intersections and vetrices in the new list of vertices according to four possible relationships between the edge and the clipping boundary discussed earlier

  6. Repeat the steps 4 and 5 for remaining edges of the clipping window.Each time the resultant list of vertices is successively passed to process the next edge of the clipping window

  7. Stop


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

  1. The Sutherland-Hodgman algorithm can be used to clip lines against a non rectangular boundary. What uses might this have? What modifications to the algorithm would be necessary? What restrictions would apply to the shape of clipping region?

  2. Explain why Sutherland-Hodgman algorithm works only for convex clipping regions?





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

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH


Pre-requisite

Knowledge of

  • Curves Generation Using

  • Bezeir Curves

    • B-Splines

Algorithm

Bezeir Curves

  1. Get Four control points say A(x A , yA ), B(x B , yB), C(xC , yC) ,D(xD , yD )

  2. Divide the curves represented by point A,B,C and D in two sections
    x AB = (x A + xB ) / 2
    y AB =
    (yA + yB ) / 2
    xBC =
    (xB+ xC ) / 2
    yBC =
    (yB+ yC ) / 2
    xCD =
    (xC + xD ) / 2
    yCD =
    (yC + yD )/ 2
    xABC = (xAB + xBC ) / 2
    yABC = (yAB + yBC ) / 2
    xBCD = (xBC + xCD) / 2
    yBCD = (yBC + yCD ) / 2
    xABCD = (xABC + xBCD ) / 2
    yABCD = (yABC + yBCD ) / 2

  1. Repeat the step 2 for section A AB, ABC, and ABCD and section

    ABCD , BCD, CD and D

  2. Repeat step 3 until we have sections so short that they can be replaced by straight lines

  3. Replace small sections by straight lines

  4. Stop


B-Splines

  1. The B-spline basis functions are defined recursively as follows:

    Ni,1(u) = 1 if ti <=u < ti+1

    = 0 otherwise.

  2. The knot values are chosen with the following rule:

    ti = 0 if i < k

    = i-k+1 if k <= i <= n

    = n-k+2 if i > n

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


p2 P4



p1 p3


Menu

1.Curves Generation using Bezier Curves

2.Curves Generation using B-Splines

3.Exit

Enter your choice.......2

p2 P4



p1 p3


Menu

1.Curves Generation using Bezier Curves

2.Curves Generation using B-Splines

3.Exit


Enter your choice.......3


Post Lab Assignment

  1. List the properties of Bezier curves.

  2. List the properties of B-Splines.

  3. Why cubic Bezier curves are chosen?

  4. What do you understand by cubic B-splines? Discuss with suitable mathematical models.








Lab Assignment 10

Title

Animation Program.

Objective

To Implement a program with animation of objects (segments) obtained by scan conversion.

References

  1. Donald Hearn and M.Pauline Baker, ”Computer Graphics with C version “,Second Edition Pearson Education

  2. Newman and Sproll, ”Principles of Interactive Computer Graphics “, Second Edition ,McGraw Hill

  3. Rogers and Adams , ”Mathematical Elements For Computer Graphics”,TMH

  4. Xiang and Plastok , ”Schaum's Outlines Computer Graphics “,Second Edition .TMH

  5. Harrington, ”Computer Graphics “ ,McGraw Hill

  6. Rogers , ”Procedural Elements for Computer Graphics” ,TMH

Pre-requisite

Knowledge of

  • All Raster Scan algorithms

    • Segmentation and its properties

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

  1. How renaming operations of segments is useful for animation?

  2. What do you mean by posting and unposting of segments?

  3. Explain the use of display and segmentation in graphics.