, Computer Graphics
About the Tutorial
To display a picture of any size on a computer screen is a difficult process.
Computer graphics are used to simplify this process. Various algorithms and
techniques are used to generate graphics in computers. This tutorial will help you
understand how all these are processed by the computer to give a rich visual
experience to the user.
Audience
This tutorial has been prepared for students who don’t know how graphics are
used in computers. It explains the basics of graphics and how they are
implemented in computers to generate various visuals.
Prerequisites
Before you start proceeding with this tutorial, we assume that you are already
aware of the basic concepts of C programming language and basic mathematics.
Copyright & Disclaimer
Copyright 2015 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials
Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy,
distribute or republish any contents or a part of contents of this e-book in any
manner without written consent of the publisher.
We strive to update the contents of our website and tutorials as timely and as
precisely as possible, however, the contents may contain inaccuracies or errors.
Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy,
timeliness or completeness of our website or its contents including this tutorial. If
you discover any errors on our website or in this tutorial, please notify us at
i
, Computer Graphics
Table of Contents
About the Tutorial .................................................................................................................................. i
Audience ................................................................................................................................................ i
Prerequisites .......................................................................................................................................... i
Copyright & Disclaimer ........................................................................................................................... i
Table of Contents .................................................................................................................................. ii
1. COMPUTER GRAPHICS – BASICS......................................................................................... 1
Cathode Ray Tube ................................................................................................................................. 1
Raster Scan ............................................................................................................................................ 2
Application of Computer Graphics ......................................................................................................... 3
2. LINE GENERATION ALGORITHM ......................................................................................... 5
DDA Algorithm ...................................................................................................................................... 5
Bresenham’s Line Generation ................................................................................................................ 6
Mid-Point Algorithm .............................................................................................................................. 9
3. CIRCLE GENERATION ALGORITHM ................................................................................... 11
Bresenham’s Algorithm ....................................................................................................................... 11
Mid Point Algorithm ............................................................................................................................ 13
4. POLYGON FILLING ............................................................................................................ 16
Scan Line Algorithm ............................................................................................................................. 16
Flood Fill Algorithm ............................................................................................................................. 17
Boundary Fill Algorithm ....................................................................................................................... 18
4-Connected Polygon ........................................................................................................................... 18
8-Connected Polygon ........................................................................................................................... 19
Inside-outside Test .............................................................................................................................. 21
ii
, Computer Graphics
5. VIEWING AND CLIPPING................................................................................................... 24
Point Clipping ...................................................................................................................................... 24
Line Clipping ........................................................................................................................................ 24
Cohen-Sutherland Line Clippings ......................................................................................................... 25
Cyrus-Beck Line Clipping Algorithm ..................................................................................................... 27
Polygon Clipping (Sutherland Hodgman Algorithm) ............................................................................. 28
Text Clipping ........................................................................................................................................ 29
Bitmap Graphics .................................................................................................................................. 31
6. 2D TRANSFORMATION ..................................................................................................... 33
Homogenous Coordinates ................................................................................................................... 33
Translation .......................................................................................................................................... 33
Rotation .............................................................................................................................................. 34
Scaling ................................................................................................................................................. 36
Reflection ............................................................................................................................................ 37
Shear ................................................................................................................................................... 38
Composite Transformation .................................................................................................................. 39
7. 3D GRAPHICS ................................................................................................................... 41
Parallel Projection ............................................................................................................................... 41
Orthographic Projection ...................................................................................................................... 42
Oblique Projection............................................................................................................................... 43
Isometric Projections ........................................................................................................................... 43
Perspective Projection ......................................................................................................................... 44
Translation .......................................................................................................................................... 45
Rotation .............................................................................................................................................. 46
Scaling ................................................................................................................................................. 47
Shear ................................................................................................................................................... 48
iii