Computer Graphics notes, Study notes for Computer Graphics. Jomo Kenyatta University of Agriculture and Technology
phoebe-jim
phoebe-jim6 April 2017

Computer Graphics notes, Study notes for Computer Graphics. Jomo Kenyatta University of Agriculture and Technology

PDF (3 MB)
144 pages
5Number of download
642Number of visits
100%on 2 votesNumber of votes
2Number of comments
Description
Introduction Computer Graphics and Primitive Algorithms: Introduction to Image and Objects, Image Representation, Basic Graphics Pipeline, Bitmap and Vector-Based Graphics, Applications of Computer Graphics, Display D...
20 points
Download points needed to download
this document
Download the document
Preview3 pages / 144

This is only a preview

3 shown on 144 pages

Download the document

This is only a preview

3 shown on 144 pages

Download the document

This is only a preview

3 shown on 144 pages

Download the document

This is only a preview

3 shown on 144 pages

Download the document
Microsoft Word - ComputerGraphics.doc

1

Syllabus S.Y.B.Sc. (IT)

SEMESTER - III, PAPER - II COMPUTER GRAPHIC

Unit I

Introduction Computer Graphics and Primitive Algorithms: Introduction to Image and Objects, Image Representation, Basic Graphics Pipeline, Bitmap and Vector-Based Graphics, Applications of Computer Graphics, Display Devices, Cathode Ray Tubes, Raster-Scan Display, Random-Scan Display, Flat Panel Display, Input Technology, Coordinate System Overview,

Scan-Conversion of graphics primitives: Scan-Conversion of a Lines (Digital Differential Analyzer Algorithm, Bresenham's Line- Drawing Algorithm, Scan-Conversion of Circle and Ellipse (Bresenham's Method of Circle Drawing, Midpoint Circle Algorithm), Drawing Ellipses and Other Conics.

Unit II Two Dimensional Transformation: Introduction to transformations, Transformation Matrix, Types of Transformations in Two-Dimensional Graphics: Identity Transformation, Scaling, Reflection, Shear Transformations, Rotation, Translation, Rotation about an Arbitrary Point, Combined Transformation, Homogeneous Coordinates, 2D Transformations using Homogeneous Coordinates

Unit III Three-dimensional transformations, Objects in Homogeneous Coordinates; Three-Dimensional Transformations: Scaling, Translation, Rotation, Shear Transformations, Reflection, World Coordinates and Viewing Coordinates, Projection, Parallel Projection, Perspective Projection.

Unit IV Viewing and Solid Area Scan-Conversion : Introduction to viewing and clipping, viewing Transformation in Two Dimensions, Introduction to Clipping, Two-Dimensional Clipping, Point Clipping, Line Clipping, Introduction to a Polygon Clipping, Viewing and Clipping in Three Dimensions, Three-Dimensional Viewing Transformations, Text Clipping

Introduction to Solid Area Scan-Conversion, Inside - Outside Test, Winding Number Method and Coherence Property, Polygon Filling, Seed Fill Algorithm, Scan-Lino Algorithm, Priority Algorithm, Scan Conversion of Character, Aliasing, Anti-Aliasing, Halftoning, Thresholding and Dithering

2

Unit V Introduction to curves, Curve Continuity, Conic Curves, Piecewise Curve Design, Parametric Curve Design, Spline Curve Representation, Bezier Curves, B-Spline Curves, Fractals and its applications.

Surface Design : Bilinear Surfaces, Ruled Surfaces, Developable Surfaces, Coons Patch, Sweep Surfaces, Surface of Revolution, Quadric Surfaces, Constructive Solid Geometry, Bezier Surfaces, B-Spline Surfaces, Subdivision Surfaces.

Visible Surfaces : Introduction to visible and hidden surfaces, Coherence for visibility, Extents and Bounding Volumes, Back Face Culling, Painter’s Algorithm, Z-Buffer Algorithm, Floating Horizon Algorithm, Roberts Algorithm.

Unit VI Object Rendering : Introduction Object-Rendering, Light Modeling Techniques, illumination Model, Shading, Flat Shading, Polygon Mesh Shading, Gaurand Shading Model, Phong Shading, Transparency Effect, Shadows, Texture and Object Representation, Ray Tracing, Ray Casting, Radiosity, Color Models.

Introduction to animation, Key-Frame Animation, Construction of an Animation Sequence, Motion Control Methods, Procedural Animation, Key-Frame Animation vs. Procedural Animation, Introduction to Morphing, Three-Dimensional Morphing.

Books : Computer Graphics, R. K. Maurya, John Wiley. Mathematical elements of Computer Graphics, David F. Rogers, J. Alan Adams, Tata McGraw-Hill. Procedural elements of Computer Graphics, David F. Rogers, Tata McGraw-Hill.

Reference: Computer Graphics, Donald Hearn and M. Pauline Baker, Prentice Hall of India. Computer Graphics, Steven Harrington, McGraw-Hill. Computer Graphics Principles and Practice, J.D. Foley, A Van Dam, S. K. Feiner and R. L. Phillips, Addision Wesley. Principles of Interactive Computer Graphics, William M. Newman, Robert F. Sproull, Tata McGraw-Hill. Introduction to Computer Graphics, J.D. Foley, A. Van Dam, S. K. Feiner, J.F. Hughes and R.L. Phillips, Addision Wesley.

3

Practical (Suggested) : Should contain at least 10 programs developed using C++. Some sample practical are listed below. 1. Write a program with menu option to input the line coordinates

from the user to generate a line using Bresenham’s method and DDA algorithm. Compare the lines for their values on the line.

2. Develop a program to generate a complete circle based on.

a) Bresenham’s circle algorithm

b) Midpoint Circle Algorithm

3. Implement the Bresenham’s / DDA algorithm for drawing line (programmer is expected to shift the origin to the center of the screen and divide the screen into required quadrants)

4. Write a program to implement a stretch band effect. (A user will click on the screen and drag the mouse / arrow keys over the screen coordinates. The line should be updated like rubber-band and on the right-click gets fixed).

5. Write program to perform the following 2D and 3D transformations on the given input figure

a) Rotate through

b) Reflection

c) Scaling

d) Translation

6. Write a program to demonstrate shear transformation in different directions on a unit square situated at the origin.

7. Develop a program to clip a line using Cohen-Sutherland line

clipping algorithm between   1 1 2 2, ,X Y X Y against a window

  min min max max, ,X Y X Y .

8. Write a program to implement polygon filling.

9. Write a program to generate a 2D/3D fractal figures (Sierpinski triangle, Cantor set, tree etc).

10. Write a program to draw Bezier and B-Spline Curves with interactive user inputs for control polygon defining the shape of the curve.

11. Write a program to demonstrate 2D animation such as clock simulation or rising sun.

12. Write a program to implement the bouncing ball inside a defined rectangular window.



4

1

COMPUTER GRAPHICS - FUNDAMENTALS

Unit Structure

1.0 Objectives

1.1 Introduction

1.2 Introduction to Image and Objects

1.3 Image Representation

1.4 Basic Graphics Pipeline

1.5 Bitmap and Vector-Based Graphics

1.6 Applications of Computer Graphics

1.7 Display Devices

1.7.1 Cathode Ray Tubes

1.7.2 Raster-Scan Display

1.7.3 Random-Scan Display

1.7.4 Flat Panel Display

1.8 Input Technology

1.9 Coordinate System Overview

1.10 Let us sum up

1.4 References and Suggested Reading

1.5 Exercise

1.0OBJECTIVES

The objective of this chapter is  To understand the basics of computer graphics.  To be aware of applications of computer graphics.  To know the elements of computer graphics.

1.1 INTRODUCTION

Computer graphics involves display, manipulation and storage of pictures and experimental data for proper visualization using a computer. It provides methods for producing images and animations (sequence of images). It deals with the hardware as well as software support for generating images.

5

Basically, there are four major operations that we perform in computer graphics:  Imaging: refers to the representation of 2D images.  Modeling: refers to the representation of 3D images.  Rendering: refers to the generation of 2D images from 3D

models.

Animation: refers to the simulation of sequence of images over time.

1.2 INTRODUCTION TO IMAGE AND OBJECTS

An image is basically representation of a real world object on a computer. Itcan be an actual picture display, a stored page in a video memory, or a source code generated by a program. Mathematically, an image is a two - dimensional array of data with intensity or a color value at each element of the array.

Objects are real world entities defined in three – dimensional world coordinates. In computer graphics we deal with both 2D and 3D descriptions of an object. We also study the algorithms and procedures for generation and manipulation of objects and images in computer graphics.

Check your Progress: 1. Define image and object. 2. How an image is represented mathematically?

1.3 IMAGE REPRESENTATION

Image representation is the approximations of the real world displayed in a computer. A picture in computer graphics is represented as a collection of discrete picture elements termed as pixels. A pixel is the smallest element of picture or object that can be represented on the screen of a device like computer.

6

Check your progress: 1. Define pixel.

1.4 BASIC GRAPHIC PIPELINE

In computer graphics, the graphics pipeline refers to a series of interconnected stages through which data and commands related to a scene go through during rendering process.

It takes us from the mathematical description of an object to its representation on the device.

The figure shown below illustrates a 3D graphic pipeline.

Figure 1.1: A 3D graphic pipeline

7

The real world objects are represented in world coordinate system. It is then projected onto a view plane. The projection is done from the viewpoint of the position of a camera or eye. There is an associated camera coordinate system whose z axis specifies the view direction when viewed from the viewpoint. The infinite volume swept by the rays emerging from the viewpoint and passing through the window is called as view volume or view pyramid. Clipping planes (near and far) are used to limit the output of the object.

The mapping of an object to a graphic device requires the transformation of view plane coordinates to physical device coordinates. There are two steps involved in this process.

(i) The window to a viewport transformation. The viewport is basically a sub – rectangle of a fixed rectangle known as logical screen.

(ii) The transformation of logical screen coordinates to physical device coordinates.

Figure : Sequence of transformation in viewing pipeline

Figure 1.2: 2D coordinate system to physical device coordinates transformation.

The figures above depict the graphic pipeline and the 2D coordinate transformation to physical device coordinates.

Representation of 3D world

objects

Clip against view volume

Transform to physical device coordinates

Transform to viewport

Project to view plane

Transform into camera

coordinates

Clip against window

Transform to physical device

coordinates

Transport to viewport

Representation of 2D world

objects

8

Check your Progress: 1. Differentiate between world coordinates system and camera

coordinate system. 2. Define view volume.

1.5 BITMAP AND VECTOR – BASED GRAPHICS

Computer graphics can be classified into two categories: Raster or Bitmap graphics and Vector graphics.

Bitmap graphics:  It is pixel based graphics.  The position and color information about the image are

stored in pixels arranged in grid pattern.  The Image size is determined on the basis of image

resolution.  These images cannot be scaled easily.  Bitmap images are used to represent photorealistic images

which involve complex color variations.

Figure 1.3 (a) An arrow image (b) magnified arrow image with pixel grid

The above figure shows a bitmap arrow image in its actual size and magnified image with pixel grid.

Vector graphics:  The images in vector graphics are basically mathematically

based images.  Vector based images have smooth edges and therefore used to

create curves and shapes.

9

Figure 1.4 (a) A rose image (b) vector description of leaf of rose

 These images are appropriate for precise illustrations but not good for photorealistic images.

 These images are easily scalable due to their mathematical structure. Figure 1.4(a) and (b) shows a rose image and vector description of leaf of rose.

Figure 1.5 (a) A bitmap image (b) a vector image

The above figure shows a bitmap and vector image of the letter A.

Check your Progress: 1. Which graphic system is better for photorealistic images? 2. In which graphic system images are easily scalable?

10

1.6 APPLICATIONS OF COMPUTER GRAPHICS

Computer graphics finds its application in various areas; some of the important areas are discussed below:

Computer-Aided Design: In engineering and architectural systems, the products are modeled using computer graphics commonly referred as CAD (Computer Aided Design).

In many design applications like automobiles, aircraft, spacecraft, etc., objects are modeled in a wireframe outline that helps the designer to observe the overall shape and internal features of the objects.

CAD applications are also used in computer animations. The motion of an object can be simulated using CAD.

Presentation graphics: In applications like summarizing of data of financial, statistical, mathematical, scientific and economic research reports, presentation graphics are used. It increases the understanding using visual tools like bar charts, line graphs, pie charts and other displays.

Computer Art: A variety of computer methods are available for artists for designing and specifying motions of an object. The object can be painted electronically on a graphic tablet using stylus with different brush strokes, brush widths and colors. The artists can also use combination of 3D modeling packages, texture mapping, drawing programs and CAD software to paint and visualize any object.

Entertainment: In making motion pictures, music videos and television shows, computer graphics methods are widely used. Graphics objects can be combined with live actions or can be used with image processing techniques to transform one object to another (morphing).

Education and training: Computer graphics can make us understand the functioning of a system in a better way. In physical systems, biological systems, population trends, etc., models makes it easier to understand.

In some training systems, graphical models with simulations help a trainee to train in virtual reality environment. For example, practice session or training of ship captains, aircraft pilots, air traffic control personnel.

11

Visualization: For analyzing scientific, engineering, medical and business data or behavior where we have to deal with large amount of information, it is very tedious and ineffective process to determine trends and relationships among them. But if it is converted into visual form, it becomes easier to understand. This process is termed as visualization.

Image processing: Image processing provides us techniques to modify or interpret existing images. One can improve picture quality through image processing techniques and can also be used for machine perception of visual information in robotics.

In medical applications, image processing techniques can be applied for image enhancements and is been widely used for CT (Computer X-ray Tomography) and PET (Position Emission Tomography) images.

Graphical User Interface: GUI commonly used these days to make a software package more interactive. There are multiple window system, icons, menus, which allows a computer setup to be utilized more efficiently.

Check your progress:

1. Fill in the blanks

(a) GUI stands for.................

(b) ............ provides us techniques to modify or interpret existing images.

2. Explain how computer graphics are useful in entertainment industry.

1.7 DISPLAY DEVICES

There are various types of displays like CRT, LCD and Plasma. We will discuss each of these three in brief.

12

CRT (Cathode Ray Tube) is one of the mostly used display technology. In CRT, a beam of electrons emitted by an electron gun strikes on specified positions on phosphor coated screen after passing through focusing and deflecting systems.

Figure 1.6 : Elements of CRT

LCD Display: LCD stands for Liquid Crystal Display o Organic molecules that remain in crystalline structure without

external force, but re-aligns themselves like liquid under external force

o So LCDs realigns themselves to EM field and changes their own polarizations

Figure 1.7 : LCD display

13

o There are two types of LCD displays:

o Active Matrix LCD:  Electric field is retained by a capacitor so that the crystal

remains in a constant state.  Transistor switches are used to transfer charge into the

capacitors during scanning.  The capacitors can hold the charge for significantly longer than

the refresh period  Crisp display with no shadows.  More expensive to produce.

o Passive matrix LCD:  LCD slowly transit between states.  In scanned displays, with a large number of pixels, the

percentage of the time that LCDs are excited is very small.  Crystals spend most of their time in intermediate states, being

neither "On" or "Off".  These displays are not very sharp and are prone to ghosting.

Plasma display:

Figure1.8 (showing the basic structure of plasma display)

o These are basically fluorescent tubes. o High- voltage discharge excites gas mixture (He, Xe), upon

relaxation UV light is emitted, UV light excites phosphors. o Some of its features are  Large view angle  Large format display  Less efficient than CRT, more power  Large pixels: 1mm (0.2 mm for CRT)  Phosphors depletion

 In CRT monitors there are two techniques of displaying images.

14

o Raster scan displays: A rectangular array of points or dots.In a raster scan system, the electron beam is swept across the screen, one row at a time from top to bottom.As the electron beam moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spots. See the figure below.

Figure 1.9 : Raster scan display

Horizontal retrace: The return to the left of the screen, after refreshing each scan line.

Vertical retrace: At the end of each frame (displayed in 1/80th to 1/60th of a second) the electron beam returns to the top left corner of the screen to begin the next frame.

Figure 1.10 (showing horizontal and vertical retrace)

15

Random scan display: Random scan display is the use of geometrical primitives such as points, lines, curves, and polygons, which are all based upon mathematical equation. In a random scan display, a CRT has the electron beam directed only to the parts of the screen where a picture is to be drawn. Random scan monitors draw a picture one line at a time. See the figure below.

Figure 1.11: Random Scan display

o Refresh rate depends on the number of lines to be displayed.

o Picture definition is now stored as a line-drawing commands an area of memory referred to as refresh display file.

o To display a picture, the system cycle through the set of commands in the display file, drawing each component line in turn.

o Random scan displays are designed to draw all the component lines of a picture 30 to 60 times each second.

o Random scan displays have higher resolution than raster systems.

There are some parameters or properties related to graphic displays like CRT:

Persistence: In case of CRT, persistence refers to the property of a phosphor defining its life time, i.e., how long they continue to emit light after the CRT beam is removed.

Resolution: The maximum number of points that can be displayed without overlap on a CRT is referred to as the resolution. In other words, it is the number of points per unit length that can be plotted horizontally and vertically.

16

Aspect ratio: It is the ratio of the number of vertical points to the number of horizontal points necessary to produce equal- length lines in both directions on the screen.

Frame buffer: Frame buffer also known as refresh buffer is the memory area that holds the set of intensity values for all the screen points.

Pixel: It refers a point on the screen. It is also known as pel and is shortened form of ‘picture element’.

Bitmap or pixmap: A frame buffer is said to be bitmap on a black and white system with one bit per pixel. For systems with multiple bits per pixel, the frame buffer is referred to as pixmap.

Graphical images - used to add emphasis, direct attention, illustrate concepts, and provide background content. Two types of graphics:

o Draw-type graphics or vector graphics – represent an image as a geometric shape

o Bitmap graphics – represents the image as an array of dots, called pixels

Three basic elements for drawing in graphics are:

o Point: A point marks a position in space. In pure geometric terms, a point is a pair of x, y coordinates. It has no mass at all. Graphically, however, a point takes form as a dot, a visible mark. A point can be an insignificant fleck of matter or a concentrated locus of power. It can penetrate like a bullet, pierce like a nail, or pucker like a kiss. A mass of points becomes texture, shape, or plane. Tiny points of varying size create shades of gray.

o Line: A line is an infinite series of points. Understood geometrically, a line has length, but no breadth. A line is the connection between two points, or it is the path of a moving point. A line can be a positive mark or a negative gap. Lines appear at the edges of objects and where two planes meet. Graphically, lines exist in many weights; the thickness and texture as well as the path of the mark determine its visual presence. Lines are drawn with a pen, pencil, brush, mouse, or digital code. They can be straight or curved, continuous or broken. When a line reaches a certain thickness, it becomes a plane. Lines multiply to describe volumes, planes, and textures.

o Plane: A plane is a flat surface extending in height and width. A plane is the path of a moving line; it is a line with breadth. A line closes to become a shape, a bounded plane. Shapes are

17

planes with edges. In vector–based software, every shape consists of line and fill. A plane can be parallel to the picture surface, or it can skew and recede into space. Ceilings, walls, floors, and windows are physical planes. A plane can be solid or perforated, opaque or transparent, textured or smooth.

Check your progress: 1. Explain different display technologies. 2. Differentiate between Raster scan and Random scan display.

1.8 INPUT TECHNOLOGY

There are different techniques for information input in graphical system. The input can be in the form of text, graphic or sound. Some of the commonly used input technologies are discussed below.

1.8.1Touch Screens A touch screen device allows a user to operate a touch

sensitive device by simply touching the display screen. The input can be given by a finger or passive objects like stylus. There are three components of a touch screen device: a touch sensor, a controller and a software driver.

A touch sensor is a touch sensitive clear glass panel. A controller is a small PC card which establishes the connection between a touch sensor and the PC. The software driver is a software that allows the touch screen to work together with the PC. The touch screen technology can be implemented in various ways like resistive, surface acoustic, capacitive, infrared, strain gauge, optical imaging, dispersive signal technology, acoustic pulse recognition and frustrated total internal reflection.

1.8.2Light pen A light pen is pen shaped pointing device which is connected

to a visual display unit. It has light sensitive tip which detects the light from the screen when placed against it which enables a computer to locate the position of the pen on the screen. Users can

18

point to the image displayed on the screen and also can draw any object on the screen similar to touch screen with more accuracy.

1.8.3 Graphic tablets Graphic tablets allow a user to draw hand draw images and

graphics in the similar way as is drawn with a pencil and paper.

It consists of a flat surface upon which the user can draw or trace an image with the help of a provided stylus. The image is generally displayed on the computer monitor instead of appearing on the tablet itself.

Check your Progress: 1. Name different types of touch screen technologies. 2. Differentiate between light pen and graphic tablet.

1.9 COORDINATE SYSTEM OVERVIEW

To define positions of points in space one requires a coordinate system. It is way of determining the position of a point by defining a set of numbers called as coordinates. There are different coordinate systems for representing an object in 2D or 3D.

1.9.1 Cartesian coordinate system It is also known as rectangular coordinate system and can

be of two or three dimensions. A point in Cartesian coordinate system can be defined by specifying two numbers, called as x – coordinate and the y – coordinate of that point.

19

.

Figure 1.12: Cartesian coordinate system

In the above figure, there are two points (2, 3) and (3, 2) are specified in Cartesian coordinate system

1.9.2 Polar coordinate system In polar coordinate system, the position of a point is defined by specifying the distance (radius) from a fixed point called as origin and the angle between the line joining the point and the origin and the polar axis (horizontal line passing through the origin).

Figure 1.13: Polar coordinate system

The above figure shows a point (r, θ) in polar coordinates.

20

Check your Progress:

Fill in the blanks 1. The position of a point is defined by specifying the distance

(radius) from a fixed point called as ……….

2. A point in Cartesian coordinate system can be defined by specifying two numbers, called as …….. and the ………… of that point.

Answers: 1. Origin 2. x - coordinate, y – coordinate.

1.10 LET US SUM UP

We learnt about computer graphics, its application in different areas. We studied various display and input technologies. We also studied basic graphic pipeline, bitmap and vector based graphics. Then we learnt the elements of computer graphics in which came to know about the terms like persistence, resolution, aspect ratio, frame buffer, pixel and bitmap. Finally we studied about the coordinate system.

1.11 REFERENCES AND SUGGESTED READING

(1) Computer Graphics, Donald Hearn, M P. Baker, PHI.

(2) Procedural elements of Computer Graphics, David F. Rogers, Tata McGraw Hill.

(3) Computer Graphics, Rajesh K. Maurya, Wiley - India

1.12 EXERCISE

1. What are the major operations that we perform on Computer Graphics?

2. Define some of the applications of Computer Graphics.

21

3. Define graphic pipeline and the process involved in it.

4. Differentiate between bitmap and vector based graphics.

5. Define the following terms: a. Persistence b. Aspect ratio c. Frame buffer d. Resolution e. Pixel

6. Define horizontal and vertical retrace.



22

2

SCAN CONVERSION OF GRAPHICS PRIMITIVES

Unit Structure

2.0 Objectives

2.1 Introduction

2.2Scan-Conversion of a Lines

2.3Scan- Conversion of Circle and Ellipse

2.3.1 Digital Differential Analyzer Algorithm

2.3.2 Bresenham's Line-Drawing Algorithm

2.4Drawing Ellipses and Other Conics

2.4.1 Bresenham's Method of Circle Drawing

2.4.2 Midpoint Circle Algorithm

2.5Drawing Ellipses and Other Conics

2.6Let us sum up

2.7References and Suggested Reading

2.8Exercise

2.0 OBJECTIVES

The objective of this chapter is  To understand the basic idea of scan conversion techniques.  To understand the algorithms for scan conversion of line,

circle and other conics.

2.1 INTRODUCTION

Scan conversion or rasterization is the process of converting the primitives from its geometric definition into a set of pixels that make the primitive in image space. This technique is used to draw shapes like line, circle, ellipse, etc. on the screen. Some of them are discussed below

23

2.2 SCAN – CONVERSION OF LINES

 A straight line can be represented by a slope intercept equation as

where m represents the slope of the line and b as the y intercept.

 If two endpoints of the line are specified at positions (x1,y1) and (x2,y2), the values of the slope m and intercept b can be determined as

 If ∆x and ∆y are the intervals corresponding to x and y respectively for a line, then for given interval ∆x, we can calculate ∆y.

Similarly for given interval ∆y, ∆x can be calculated as

 For lines with magnitude |m| < 1, ∆x can be set proportional to a small horizontal deflection and the corresponding horizontal deflection is et proportional to ∆y and can be calculated as

 For lines with |m|>1, ∆y can be set proportional to small vertical deflection and corresponding ∆x which is set proportional to

horizontal deflection is calculated using

The following shows line drawn between points (x1, y1) and (x2, y2).

Figure 2.1 : A line representation in Cartesian coordinate system

24

2.2.1 Digital Differential Analyzer (DDA) Algorithm

 Sampling of the line at unit interval is carried out in one coordinate and corresponding integer value for the other coordinate is calculated.

 If the slope is less than or equal to 1( |m| ≤ 1), the coordinate x is sampled at unit intervals (∆x = 1) and each successive values of y is computed as

where k varies from 1 to the end point value taking integer values only. The value of y calculated is rounded off to the nearest integer value.

 For slope greater than 1 (|m| > 1), the roles of y and x are reversed, i.e., y is sampled at unit intervals (∆y = 1) and corresponding x values are calculated as

 For negative value slopes, we follow the same procedure as above, only the sampling unit ∆x and ∆y becomes ‘-1’ and

Pseudocode for DDA algorithm is as follows LineDDA(Xa, Ya, Xb, Yb) // to draw a line from (Xa, Ya) to (Xb, Yb)

{ Set dx = Xb - Xa, dy = Yb - Ya; Set steps = dx; SetX = Xa, Y = Ya; int c = 0; Call PutPixel(Xa, ya); For (i=0; i <steps; i++)

{ X = X + 1;

c = c + dy; // update the fractional part If (c > dx)

{ // (that is, the fractional part is greater than 1 now

Y = y +1; // carry the overflowed integer over c = c - dx // update the fractional part

Call PutPixel(X, Y); } }

}

25

2.2.2 Bresenham’s Line Drawing Algorithm

This line drawing algorithm proposed by Bresenham, is an accurate and efficient raster-line generating algorithm using only incremental integer calculations.

For lines |m| ≤ 1, the Bresenham’s line drawing algorithm

I. Read the end points of the line and store left point in (x0, y0)

II. Plot (x0, y0), the first point.

III. Calculate constants ∆x, ∆y, 2∆y and 2∆y - 2∆x, and obtain a decision parameter p0

IV. Perform the following test for each xk, starting at k = 0 if pk< 0, then next plotting point is (xk+1, yk) and

Otherwise, the next point to plot is (xk+1, yk+1) and

V. Repeat step 4 ∆x times. For a line with positive slope more than 1, the roles of the x

and y directions are interchanged.

Check your progress:

1. Fill in the blanks

(a) ............of the line at unit interval is carried out in one coordinate and corresponding integer value for the other coordinate is calculated.

(b) Bresenham's line drawing algorithm is an accurate and efficient raster-line generating algorithm using only ................calculations.

2. Compare DDA and Bresenham's line drawing algorithm.

Answers: 1(a) sampling (b) incremental integer

.

comments (2)
note is not downloading dear

This is only a preview

3 shown on 144 pages

Download the document