UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie...

71
UNIT-II Poly gons

Transcript of UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie...

Page 1: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

UNIT-II Polygons

Page 2: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Syllabus

UNIT 2

Polygons (08 Hours, 16 marks)

Polygons

Types of Polygons

Polygons filing

Scan conversion algorithm

Segments

Page 3: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Polygons

Introduction

Terminal point

Polyline

Polygon

Page 4: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Types of polygon

Convex

Concave

Polygons

Page 5: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Representation of Polygons

Polygon drawing Primitive approach

Trapezoid primitive approach

Line and Point approach

Polygon drawing Primitive approach

Some graphics devices supports polygon drawing

primitive approach. They can directly draw the polygon

shapes. On such a devices polygons are saved as a unit.

Polygons are drawn line by line using standard graphics

line command.

Page 6: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Representation of Polygons(Cont….)

Trapezoid primitive approach

Trapezoids are formed from 2 scan lines & 2 line

segments.

Every polygon is broken up into trapezoids & it is

represented as a series of trapezoids.

Page 7: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Representation of Polygons(Cont….)

Line and Point approach

Polygons are represented using lines & points.

A polygon is represented as a unit & it is stored in display

file.

In display file polygon can not be stored only with series of

line commands because they do not specify how many of the

following line commands are the part of the polygon.

Therefore new command is used in the display file to

represent polygons.

The opcode for new command itself specify the number of

line segments in the polygons.

Page 8: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Representation of Polygons(Cont….)

Line and Point approach

Page 9: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Entering Polygons

It describes how to enter polygon command & data into

display file.

We know that, we have to enter number of sides & the

coordinates of the vertex points.

This can be entered using following algorithm

Page 10: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

An Inside Test

After Entering ,We can draw the outline of the polygon.

To show the polygon as a solid object we have to set the

pixels inside the polygon as well as pixels on the

boundary of it.

To determine the pixel inside or outside the polygon; an

inside test is applied.

1. Even-odd method of determining polygon inside point.

2. Winding-Number Method of determining polygon inside

point.

Page 11: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Even-odd method of determining polygon inside point

Count how many intersections

of the line segment with the

polygon boundary occur.

If there are odd number of

intersections ,then the point

(to be tested) is inside ;

otherwise point(pixel) is

outside.

This method is called the

even-odd method of

determining polygon inside

points.

Page 12: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Even-odd method of determining polygon inside

point(cont…)

If the intersection point is vertex of the polygon then we have to look at the other endpoints of the two segments which meet at that vertex.

If these points lie on the same side of the constructed line, then the point counts as even number of intersections.

If they lie on the opposite sides of the constructed line , then the point is counted as a single ( odd) intersection

Page 13: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Winding-Number Method of determining polygon

inside point

Give direction number to each boundary line crossed.

After giving direction numbers we have to take sum of theses direction numbers which indicates whether the point in inside the polygon or not.

The sum of the direction numbers for the sides that cross the constructed horizontal line segment is called the winding number for the test point.

For polygons or two dimensional objects the point is said to be inside when the value of winding number is nonzero.

Page 14: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Polygon Filling

Filling the polygon means highlighting all pixels which lie inside

the polygon with any color other than background color.

Algorithm for polygon filling

Seed Fill Algorithm

Flood Fill Algorithm

Boundary Fill Algorithm/edge-

Fill Algorithm

Scan Line Algorithm

Page 15: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Seed Fill Algorithm

To fill a polygon is to start from a given “seed”, point

known to be inside the polygon & highlight outward from

this point i.e. Neighboring pixels until we encounter the

boundary pixels.

This approach is called seed fill because color flows from

the seed pixel until reaching the polygon boundary.

1. Boundary Fill algorithm OR Edge Fill algorithm

Algorithm that fill boundary defined regions are called

boundary fill algorithms or edge fill algorithms

In this method, edges of polygons are drawn.

Page 16: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Boundary Fill algorithm OR Edge Fill algorithm

Algorithm that fill boundary defined regions are called

boundary fill algorithms or edge fill algorithms

In this method, edges of polygons are drawn.

Starting with some seed , any point inside polygon we examine

the neighboring pixels to check whether the boundary pixel is

reached.

If boundary pixels are not reached, pixels are highlighted &

the process is continued until pixels are reached.

Boundary defined regions may be either 4-connected or 8-

connected as shown in figure.

Page 17: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Fig.Partial Filling resulted using 4-connected algorithm

Page 18: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Procedure shows 4-connected region using Boundary Fill Algorithm

Page 19: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Flood Fill algorithm

In this algorithm, we can fill areas by replacing a specified

interior color instead of searching for a boundary color.

Like boundary fill algorithm, here we start with some seed &

examine the neighboring pixels.

However, here pixels are checked for a specified interior

color instead of boundary color & they are replaced by new

color.

Either 4-connected or 8-connected approach is used for filling

the polygon.

Page 20: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Procedure shows 8-connected region using Flood Fill algorithm

Page 21: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Scan Line algorithm

This is another approach to fill polygon, which uses an inside test i.e. to check whether the pixel is inside the polygon or outside the polygon & then highlight pixels which lie inside the polygon.

It avoids the need for a seed pixel but it requires some computations.

It uses scan line.

Such method fills horizontal pixel spans across scan lines, instead of proceeding to 4-connected or 8-connected neighboring points.

This is achieved by identifying the rightmost & leftmost pixels of the seed pixel & then drawing horizontal line (scan line) between these 2 boundary pixels.

This procedure is repeated with changing the seed pixel above & below the line just drawn until complete polygon is filled.

Page 22: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Scan Line algorithm(Cont..)

This algorithm first finds the largest & smallest y values of polygon.

It then start from largest y value & works its way down.(left to right like raster)

Important task in the scan line algorithm is to find the intersection points of the scan line with the polygon boundary.

Apply inside test for this purpose.

If there are odd number of intersections ,then the point (pixel) is inside ; otherwise pixel is outside

If the intersection point is vertex of the polygon then we have to look at the other endpoints of the two segments which meet at that vertex.

If these points lie on the same side(either up or down) of the constructed line, then the point counts as even number of intersections.

Page 23: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Scan Line algorithm(Cont..)

If they lie on the opposite side(one on upside and other one on

downside) of the constructed line ,then the point is counted as a

single (odd) intersection.

Page 24: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

It is necessary to calculate x intersection points for scan line

with every polygon side.

We can simplify these calculations by using coherence

properties.

It’s a property of any scene by we can relate one part of

scene with the other parts of a scene.

Here we can use a slope of an edge as a coherence property.

By using this property we can determine the x intersection

value on the lower scan line if x intersection value for current

scan line is known. This is given as-

Page 25: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

X i+1 = Xi – (1/m)

Where m is the slope of the edge

As we scan from top to bottom value of y coordinates between

the two scan line changes by 1.

Y i+1 = Yi – 1

Page 26: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Filling with Patterns

Pattern is a small group of pixels with a fixed color combination used to fill the particular area in the picture.

Can be any shape.

Tiling

Tiling pattern

Pattern fill can be implemented by modifying the scan line algorithm. So that selected pattern is superimposed onto the scan lines.

In the pattern filling it is necessary to decide which pixel in the pattern corresponds to the current pixel of the primitive. Relating area of the pattern with the area of the primitive is known as anchoring.

Two methods to implement pattern filling

Stamping

True Filling

Page 27: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Filling with Patterns(Cont..)

Page 28: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Scan conversion

The process of representing pictures or graphics object as a collection of discrete pixels is called scan conversion.

It’s a process of organizing graphics picture into precise pattern required by graphics display is called scan conversion.

Display file store the information about lines & character whereas scan conversion gives the information about every pixel on the screen.

four different ways (methods) to accomplish scan conversion-

1) Real Time Scan Conversion

2) Run Length Encoding

3) Cell Encoding

4) Solid Area Scan Conversion

Page 29: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Real Time Scan Conversion

In a real time scan conversion the picture is randomly

represented in terms of visual attributes & geometric properties.

The color, shade & intensity are the examples of visual attributes

of the picture whereas x-y coordinates, slope & text are the

typical geometric properties of the picture.

Display processor scans through these geometric properties &

visual attributes calculates the intensity of every pixel on the

screen during the presentation of each frame.

Page 30: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Run Length Encoding

Picture can be defined by pixel intensity & number of successive pixels on given scan line with the same intensity i.e. Run length. Such a representation of a picture is called run length encoding.

The first number is the intensity & second is the number of successive pixel on that scan line with same intensity.

In pixel by pixel storage i.e. one piece of information for each pixel require 225 intensity values for the 15*15 raster.

However ,with run length encoding the complete picture is encoded with only 102 numbers.

Color picture is encoded in 4 groups- Red Intensity(RI),Green Intensity(GI),Blue Intensity(BI), & Run Length (RL).

Run length encoding technique can also be used for solid objects.

Page 31: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Run Length Encoding(Cont…)

Figure shows a simple picture on 15*15 raster & associated

encoding for each scan line.

Encoded data in 2 groups – Intensity(I) & Run length (RL).

Page 32: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Run Length Encoding(Cont…)

Picture is stored in compressed form with compression ratio

approaching 10:1

Less memory is required to store picture.

Saves storage space.

Saves transmission time.

As run lengths are stored sequentially ,adding or deleting lines

or texts from the picture is difficult and time consuming.

It requires extra overhead in encoding & decoding the picture.

For short runs, expansion may result instead of compression.

Page 33: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Cell Encoding

Picture is encode the raster as a set of rectangular or square

areas called cell encoding.

The set of rectangular or square area used to represent

minimum of information is called cell.

The entire screen is divided into cells & the size of cell is kept

large to contain one character.

Ex.Screen may be divided into areas containing 8*8 pixels

i.e.cell height & cell width both are 8 pixels wide.

There are 64*64 cells for a 512*512 display or 60*80 cells for

a 480*640 video compatible display.

Usually a cell of 8*8 is used for a 5*7 dot matrix character

display & 8*10 pixel is used for 7*9 dot matrix characters.

Page 34: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon
Page 35: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Solid Area Scan Conversion

Raster scan device can represent solid areas.

The generation of solid areas from simple edge or vertex

description is called Solid Area Scan Conversion/Polygon

filing.

For generating solid area – 2 techniques

1. Scan Conversion

2. Seed Fill

1. Scan Conversion :- Determine whether point is inside or outside

polygon.

2. Seed Fill :- Seed ( which is inside the polygon) is used.

Search adjacent points & fill the polygon.

Page 36: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Raster Scan Display

• Electron beam swept across the screen one row at a time from top to bottom.

• As the beam moves across each row the beam intensity is turned on and off to

create pattern of illuminated spots.

• Picture definition stored in memory area called frame buffer or refresh buffer

• This memory area actually holds the set of intensity values for all screen points.

These stored intensity values are then retrieved from buffer and painted on

screen one row at a time.

GUI

Plotting of graphics and charts

Page 37: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Flat Panel Display

Reduced volume, weight, power requirements compared to CRT

Thinner than CRT

Types

Emissive: convert electrical energy into light energy.

Non-emissive: They use optical effects to convert sunlight or

light from other source into graphics pattern.

Page 38: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Plasma Panel Display

It writes images on the display surface point by point.

It consists of two plates of glass with thin closely spaced gold electrodes.

The gold electrodes are attached to the inner faces and covered with dielectric material. These are attached as a series of vertical conducting ribbons on one glass plate and a set of horizontal ribbons to the other glass plate. The space between two glass plates is filled with neon-based gas and sealed.

By applying voltages between the electrodes the gas within the panel is made to behave as if it were divided into tiny cells, each one independent of its neighbors.

Page 39: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Plasma Panel Display

Page 40: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Plasma Panel Display(Continue….)

These independent cells are made to glow by placing a firing voltages of about 120 volts across it by means of the electrodes. The glow can be sustained by maintaining a high frequency.

Advantages

Refreshing not required

Produce a very steady image, totally free of flicker

Less bulky than a CRT

It has the flat screen and is transparent

Disadvantages

Relatively poor resolution of about 60dots per inch.

It requires complex addressing and writing

Costlier than the CRT.

Page 41: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

LCD

The compounds have a crystalline arrangement of molecules, they flow like a liquid

Nematic(Thread like) liquid crystal compounds

Two glass plates each containing a light polarizer at right angles to the other plate sandwich the liquid-crystal material. Rows of horizontal transparent conductors are built into one glass plate and columns of vertical conductors are put into the other plate. The intersection of two conductors defines a pixel position.

In the ON state polarized light passing through material is twisted so that it will pass through the opposite polarizer.

To turn OFF the pixel we apply a voltage to the two intersecting conductors to align the molecules so that the light is not twisted.

Page 42: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

LCD(Continue….)

Page 43: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Interactive Devices

Joystick

Page 44: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Interactive Devices

Touch panels

Page 45: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Interactive Devices

Light Pens

Page 46: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Output Devices

Scanners

Page 47: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Output Devices

Digitizers/ Tablets

Page 48: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Line Generation algorithms

Some useful terms/concepts for understanding Line Generation

algorithms

Output primitives

Line

Point

2D,3D

Equation of line

Slope

Intercept

Line segments

Length of the line

Vectors

Incremental methods/ Incremental algorithm

Page 49: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Line Generation Algorithms/ Line Drawing Algorithms

The process of turning on the pixels for a line segments is called

vector generation or line generation.

General requirements of line drawing algorithm can be

fulfilled by following characteristics of line.

The line should appear as a straight line and it should start and end

accurately.

The line should be displayed with constant brightness along its length

independent of its length and orientation.

The line should drawn rapidly.

Page 50: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Different Lines and their orientation

Page 51: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Few Line Generation Algorithms based on incremental

method/ incremental Algorithm.

Vector generation/DDA Algorithm/DDA Line Drawing

algorithm. Where DDA-Digital Differential Analyzer

Bresenham’s Line Algorithm/ Bresenham’s Line Drawing

Algorithm

Generalized Bresenham’s Line Algorithm/ Bresenham’s Line

Drawing Algorithm

Page 52: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon
Page 53: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Line Styles

Dotted Line

Dashed line

Thick Line

Page 54: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Thick Lines

So far we have discussed line drawing algorithms where

thickness of line is one pixel

In raster scan displays it is possible to draw lines with thickness

greater than one pixel.

We have to run two line drawing algorithms in parallel to find

the pixels along the line edges and while stepping along the

line we have to turn on all the pixels which lie between the

boundaries.

Page 55: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Thick Lines(Cont…)

Page 56: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Antialiasing

In the line drawing algorithms we have seen that all rasterized

locations do not match with the true line and we have to select

the optimum raster locations to represent a straight line. This

problem is severe in low resolution screens. In such screens line

appears like a stair step. This effect is known as Aliasing .

The aliasing effect can be reduced by adjusting intensities of

the pixels along the line. The process of adjusting intensities of

the pixels along the line to minimize the effect of aliasing is

called Antialiasing.

Page 57: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

The aliasing effect can be minimized by increasing resolution

of the raster display.

As shown in the figure, line looks better in twice resolution but

this improvement comes at the price of quadrupling the cost of

memory, bandwidth of memory and scan-conversion time. Thus

increasing resolution is an expensive method for reducing

aliasing effect.

Page 58: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Unweighted Area Sampling

Many times the line passes between two pixels. In theses cases line drawing algorithm selects the pixel which is closer to the true line.

In antialiasing instead of picking closest pixel ,both pixels are highlighted. However ,their intensity values may differ.

In unweighted are sampling the intensity of pixel is proportional to the amount of line are occupied by the pixel.

This technique produces noticeably better results than does setting pixels either to full intensity or to zero intensity.

Page 59: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Unweighted Area Sampling(Figure)

Page 60: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Weighted Area Sampling

Small area in the corner of the pixel contributes just as much as

does an equal-sized area near the pixels center. To avoid this

problem even better strategy is used in the weighted area

sampling.

Page 61: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Few Circle Drawing/Generation Algorithms

Vector generation/DDA Algorithm/DDA Circle Drawing

algorithm. Where DDA-Digital Differential Analyzer.

Bresenham’s Algorithm/ Bresenham’s Circle Drawing Algorithm

Midpoint Algorithm

Page 62: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Bresenham’s Circle Drawing Algorithm

If the circle is to be plotted efficiently the use of trigonometric and power functions must be avoided.

It is desirable to perform the calculations necessary to find the scan-converted points with only integer addition, subtraction and multiplication by powers of 2.

This algorithm considers the eight-way symmetry of the circle to generate it. It plots 1/8th part of the circle i.e. from 90o to 45o

,the x moves in positive direction and the y moves in negative direction.

To achieve best approximation to the true circle we have to select those pixels in the raster that fall the least distance from the true circle.

Page 63: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Bresenham’s Circle Drawing Algorithm(Cont….)

It can be noticed that if points are generated from 90o to 45o,

each new point closest to the true circle can be found by

applying either of the two options:

Increment in positive x direction by one unit or

Increment in positive x direction and negative y direction both by

one unit.

Therefore a method of selecting between these two choices is

all that is necessary to find the points closest to the true circle.

Page 64: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Bresenham’s Circle Drawing Algorithm(Cont….)

Page 65: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Midpoint Circle Drawing Algorithm

The midpoint circle drawing algorithm also uses the eight-way

symmetry of the circle to generate it.

It plots 1/8th part of the circle, from 90o to 45o.

Page 66: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Character Generation Methods

Letters ,numbers and other characters can be displayed in a

variety of sizes and styles to label drawing.

Mostly characters are built into graphics display devices

usually as hardware but sometimes through software.

There are mainly three methods for character generation as,

Stroke method

Starbust method

Bitmap method

Page 67: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Stroke method

uses small segments to generate a character.

Lines segment are generated like strokes of a pen to form

characters.

We can build our own stroke method character generator by

calls to the line drawing algorithm and necessary.

It supports scaling of characters by changing length of line

segment.

Page 68: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Starbust method

In this method a fix pattern of line segments are used to

generate a characters.

Total 24 line segments from these 24 segments required to

display for particular character are highlighted.

It is called starbust because of its characteristics appearance.

Patterns for particular characters are stored in the form of 24-

bit code each bit representing. One line segment set to 1 or 0.

This method not used now a days.

Page 69: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Starbust method(Cont…)

Disadvantages

24-bits required to represent character hence more memory

required.

Requires code conversion software to display character from

its 24-bit code.

Character quality is poor and worst for curved shaped

characters.

Page 70: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Bitmap method

This method also called as Dot Matrix.

In this method characters are represented by an array of dots

in matrix form. For example 5 × 7 or 7 × 9 or 9 × 13 array.

Character is placed on screen by copying pixel value from

character array into some portion of screens frame buffer.

Page 71: UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie inside the polygon with any color other than background color. Algorithm for polygon

Thank you