Unit - 1

Introduction and Line Generation

Q1) What is computer graphics write in short.

A1)

The more complex objects and operations are constructed by the primitives that are low-level objects or the operations from a higher level.

The primitives are the basic elements used in computer graphics.

Lines, curves, and polygons are the basic elements that are used to create complex graphical images on the computer.

The operations of basic primitives are used in a programming language.

To create any drawing on the computer these primitives are used as software.

To store the type of display the data is important.

Q2) How many types of computer graphics? Explain in short.

A2)

The meaningful information that can be represented in pictorial form on the computer is called graphics.

There are two types of computer graphics.

Raster Graphics:

The image in raster graphics is represented or drawn using pixels.

It is also known as a bitmap image.

The image is in a sequence of smaller pixels.

In short, the raster graphics shown image is a large number of pixels together.

Vector Graphics:

Vector graphics use mathematical formulae to draw different types of shapes, lines, objects, and so on.

The data in graphics are manipulated and represented graphically.

Q3) Write a short note on a random scan display, raster scan display.

A3)

Random Scan Display

The electron beam is directed only to the area where the picture has to be drawn.

It is also called a vector display.

It draws the picture as one line at a time.

In any specified sequence, the picture line can be drawn or refresh.

For ex. Pen plotter

Raster Scan Display

The raster scan display uses the CRT method.

It is based on television technology.

The electron beam in the raster scan sweeps from top to bottom by covering one row at a time.

The beam is intensity on and off is creating the pattern of the illuminated pattern of spots as it moves from each row.

The memory area is known as refresh buffer or frame buffer as it stores picture definition.

The memory area holds intensity values for all screen points.

Q4) Write short note on frame buffer and video control.

A4)

Frame Buffer

The frame buffer is the video output device that drives a video display from the memory buffer as a complete set of data.

The images are stored in terms of a pixel by pixel.

The memory can be disc, integrated circuits, etc.

Video Controller

It is a key hardware component.

It is also known as a video or graphics card.

It allows the computer to generate graphics information for any video display device

Q5) Write a short note on points and lines.

A5)

Points: It is a basic element of computer graphics. It is completely defined by the pair of coordinates as (x, y).

Lines:

The line is the special build block of graphics it is used in various platforms such as line graphs, bar and pie charts, 2D and 3D graphs in mathematical function, engineering drawing, and architectural plans.

The straight line is developed in two ways as a structural method which shows the pixels that should be set before drawing the line and a conditional method that is used to find the pixels which should be set next.

Q6) Explain line generation algorithms in brief.

A6)

A line connects two points.

It is a basic element in graphics.

Two points are required to draw a line as X0, Y0, and X1, Y1.

Q7) Explain Digital Differential Analyzer (DDA) line generation algorithm with an example.

A7)

The digital differential analyzer (DDA) is a simple line generation algorithm.

The line connects two points.

Hence to draw any line we need at least two points.

Hence, we prefer one point as (X1, Y1) and the second point is (X2, Y2).

Following are some steps to perform the DDA algorithm.

Step 1: Get the input (X1, Y1) and (X2, Y2)

Step 2: Calculate the slope of the line using inputs.

M= Y2-Y1/X2-X1

Step 3: according to the slope of the line, we need to decide the case which gives the next point of the line.

Following are three cases are used to solve the DDA algorithm.

Case 1: m<1 Xn=X1+1 and Yn=Y1+m

Case 2: m>1 Xn=X1+1/m and Yn=Y1+1

Case 3: m=1 Xn=X1+1 and Yn=Y1+1

Step 4: the process continues till we get the input point (X2, Y2). Then the line generates with the help of coordinates that we occur.

Example:

Inputs: (X1, Y1) = (0,0) and (X2, Y2) = (8,4)

M= Y2-Y1/X2-X1

M=4-0/8-0

M = 0.5

Here M=0.5

Hence follow case 1 where M<1 then Xn=X1+1 and Yn=Y1+m

X1 | Y1 | Xn | Yn |

0 | 0 | 0 | 0 |

0+1=1 | 0+0.5=0.5 | 1 | 1 |

1+1=2 | 0.5+0.5=1 | 2 | 1 |

2+1=3 | 1+0.5=1.5 | 3 | 2 |

3+1=4 | 1.5+0.5=2 | 4 | 2 |

4+1=5 | 2+0.5=2.5 | 5 | 3 |

5+1=6 | 2.5+0.5=3 | 6 | 3 |

6+1=7 | 3+0.5=3.5 | 7 | 4 |

7+1=8 | 3.5+0.5=4 | 8 | 4 |

At last, we get the last point (X2, Y2) = (8,4) we stop.

Q8) Explain Bresenham’s Line Drawing Algorithm with an example.

A8)

It is another line generation algorithm known as the incremental scan conversion algorithm.

It uses only integer calculations.

Following are steps to perform Bresenham’s algorithm.

Step 1: Get the input (X1, Y1) and (X2, Y2)

Step 2: Find decision parameter Pk and P0

Pk=2 ∆Y - ∆X

Where ∆X=X2-X1 and ∆Y=Y2-Y1

Step 3: according to the value of Pk, we need to decide the case which gives the next point of the line.

Following are three cases are used to solve Bresenham’s algorithm.

Case 1: Pk>0, Pk+1=Pk + 2 ∆Y - 2 ∆X

Where Xn=X1+1 and Yn=Y1+1

Case 2: Pk<0, Pk+1=Pk + 2 ∆Y

Where Xn=X1+1 and Yn=Y1+1

Step 4: the process continues till we get the input point (X2, Y2). Then the line generates with the help of coordinates that we occur.

Example:

Step 1: Get the input (X1, Y1) and (X2, Y2)

(X1, Y1) = (20,10) and (X2, Y2) = (30,18)

Step 2: find decision parameter Pk and P0

Pk=2 ∆Y - ∆X

Where ∆X=X2-X1=30-20=10 and ∆Y=Y2-Y1=18-10=8

Hence, Pk=2 ∆Y - ∆X = 2*8-10= 16-10=6

Pk | Xn | Yn |

>0 | 21 | 11 |

2>0 | 22 | 12 |

-2<0 | 23 | 12 |

14>0 | 24 | 13 |

10>0 | 25 | 14 |

6>0 | 26 | 15 |

2>0 | 27 | 16 |

-2<0 | 28 | 16 |

14>0 | 29 | 17 |

10>0 | 30 | 18 |

At last, we get the last point (X2, Y2) = (30,18) we stop.

Q9) Explain Circle Generating Algorithms in brief.

A9)

It is difficult to draw a circle than a line drawing.

The equation of a circle is r2=X2+Y2

There is some circle drawing algorithm as follows:

Q10) Explain Digital Differential Analyzer (DDA) Circle Drawing Algorithm.

A10)

This algorithm uses the incremental method to draw each point.

The algorithm calculates the starting point and by the value of E, the value of x and y coordinates will be increased and decreases respectively.

The equation of a circle is r2=X2+Y2

To calculate the value of E,

We have a formula,

2n-1<=r <=2n where r = radius of circle

E=2^-n=1/2^n

E is used to calculate the value of circle point which helps to draw a circle as

X2=X1+E Y1 for x and

Y2=Y1- E X2 for y

Algorithm:

Step 1: Read the radius r of the circle and calculate the value of E

Step 2: Start X=0 i.e., initial point and

Start Y=r i.e., radius

Step 3: X1=0 and Y1=r

Step 4:

Do {

X2=X1+E Y1

Y2=Y1-E X2

//Here X2 represents Xn+1 and X1 represent Xn

//Xn is from the equation of a circle

Plot (int X2, int Y2)

//here swapping points to calculate next closest pixel

X1=X2

Y1=Y2

}

While ((Y1-Y0) < E or (X0-X1)>E)

//here, while the condition is to check the current position, is a starting point or not, if the current point is not starting point, then repeats.

Step 5: stop

Q11) Explain Bresenham’s Circle Drawing Algorithm with an example.

A11)

The following circle shows the 8 portions from which we will occur the coordinates of the circle.

Algorithm:

Step 1: input of circle radius r, (Xc, Yc)

Step 2: initial value X=0 and Y=r

Step 3: plot pixel (X+Xc, Y+Yc)

Step 4: decision parameter Pk=3-2r

Step 5: Start of the loop

If Case 1:

If Pk<0 then Pk+1=Pk+4X+6

Where Xn=X+1 and Yn=Y

Else Case 2:

If Pk>0 then Pk+1=Pk+4(X-Y) +10

Xn=X+1 and Yn=Y-1

Step 6: X=Y stop

Example:

Given R=10

Hence Y=R

If we want to draw a circle in the center then we have given the center points as (Xc, Yc) = (2,2)

Decision parameters are Pk and P0.

P0=3-2r

Here, P0=3-2*10=3-20=-17

Hence Pk=P0= -17

Following are two cases that will be decided according to Pk’s value.

Case 1:

If Pk<0 then Pk+1=Pk+4X+6

Where Xn=X+1 and Yn=Y

Case 2:

If Pk>0 then Pk+1=Pk+4(X-Y) +10

Xn=X+1 and Yn=Y-1

Pk | Xn | Yn |

-17<0 | 0 | 10 |

-17+4*1+6=-7<0 | 1 | 10 |

-7+4*2+6=7>0 | 2 | 10 |

7+4*(3-9) +10=-7<0 | 3 | 9 |

-7+4*4+6=15>0 | 4 | 9 |

15+4*5-4*8+10=-7<0 | 5 | 8 |

-7+4*6+6=23>0 | 6 | 8 |

| 7 | 7 |

Here X=Y then stop

Q12) Explain the Mid-Point Circle Drawing Algorithm with an example.

A12)

Algorithm:

Step 1: input of circle radius r, (Xc, Yc)

Step 2: initial value X=0 and Y=r

Step 3: plot pixel (X+Xc, Y+Yc)

Step 4: decision parameter Pk=1-r

Step 5: Start of the loop

If Case 1:

If Pk<0 then Pk+1=Pk+2X+1

Where Xn=X+1 and Yn=Y

Else Case 2:

If Pk>0 then Pk+1=Pk+2X+1-2Y

Xn=X+1 and Yn=Y-1

Step 6: X=Y stop

Example:

Given R=10

Hence Y=R

If we want to draw a circle in the center then we have given the center points as (Xc, Yc) = (2,2)

Decision parameters are Pk and P0.

P0=1-r

Here, P0=1-10=-9

Hence Pk=P0= -9

Following are two cases that will be decided according to Pk’s value.

Case 1:

If Pk<0 then Pk+1=Pk+2X+1

Where Xn=X+1 and Yn=Y

Case 2:

If Pk>0 then Pk+1=Pk+2X+1-2Y

Xn=X+1 and Yn=Y-1

Pk | Xn | Yn |

-9<0 | 0 | 0 |

-9+2*1+1=-6<0 | 1 | 10 |

-6+2*2+1=-1<0 | 2 | 10 |

-1+2*3+1=6>0 | 3 | 10 |

6+2*4+1-2*9=-3<0 | 4 | 9 |

-3+2*5+1=8>0 | 5 | 9 |

8+2*6+1-2*8=5>0 | 6 | 8 |

| 7 | 7 |

Now X=Y hence we stop the loop.

If we want to draw the circle at the center then we need coordinates as (Xc, Yc) Then coordinates becomes X=Xn+Xc and Y=Yn+Yc.

Q13) Write a short note on the Parallel Version of line and circle Algorithms.

A13)

The parallelization is based on the line drawing and circle drawing algorithm.

The raster scan method is used to define the parallelization.

The line algorithm approaches a perfect speedup of P as the line length approaches infinity.

The circle algorithm approaches a speedup greater than 0.9 P as the circle radius approaches infinity.

Each algorithm shows the smaller setup over-head.

The three integer multiplies and one or two integer divides with seven loop iterations for line algorithm are used in the setup.

Four integer multiplies and no divides and one loop iteration are used in circle setup.

This parallelization process can be extended for other approaches in future work.