B190230a-Cs411 Assign 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

BINDURA UNIVERSITY OF SCIENCE EDUCATION

NAME MAVIS T.

SURNAME MUNDENDA

REG. NUMBER B190230A

LEVEL 4.2

PROGRAMME I.T

COURSE CODE CS411

COURSE NAME COMPUTER GRAPHICS

ASSIGNMENT 2

Page 1 of 8
Cs411 assignments
Due date 15 october 2022
Submit via email. [email protected]

Assignment 2

a) List five graphic primitives and give five attributes for an individual primitive class or
for groups of output primitives. [15]

Primitives includes points, lines, characters


Attributes are the properties of the output primitives; that is, an attribute describes how a
particular primitive is to be displayed. They include intensity and color specifications, line
styles, text styles, and area-filling patterns. The appearance of displayed characters is controlled
by attributes such as font, size, color and orientation. The basic attributes of a straight-line
segment are its:
 Type: solid, dashed and dotted lines.
 Width: the thickness of the line is specified.
 Color: a color index is included to provide color or intensity properties.

b) Define the following terms used in Computer graphics


i. Persistence

Persistence is the time it takes the emitted light from the screen to decay one tenth of its
original intensity

ii. Resolution

The maximum number of points that can be displayed without an overlap on a CRT i

iii. Aspect ratio

The ratio of vertical points to the horizontal points necessary to produce length of lines in both
directions of the screen

c) Differentiate

i. horizontal and vertical retrace [4]

The return to the left of the screen after refreshing each scan line is called as the horizontal
retrace.
Vertical retrace: At the end of each frame the electron beam returns to the top left corner of
the screen to the beginning the next frame
ii. raster scan and random scan systems [6]

Page 2 of 8
The Raster scan system is a scanning technique in which the electrons sweep from top to
bottom and from left to right. The intensity is turned on or off to light and un-light the pixel.
Random scan is a method in which the display is made by the electronic beam which is
directed only to the points or part of the screen where the picture is to be drawn.

Page 3 of 8
(34 Marks)
Quiz 1

a) Describe three different methods of smoothly joining two-line segments. [9]


 Miter joins: Accomplished by extending the outer boundaries of each of the two lines
until they meet.
 Round join: produced by capping the connection between the two segments with a
circular boundary whose diameter is equal to the line width.
 Bevel join: generated by displaying the line segments with butt caps and filling in the
triangular gap where the segments meet

b) Antialiasing methods compensate for the under-sampling process when applied to


displayed raster lines. Briefly explain the following methods of antialiasing.

i. antialiasing by super sampling or post filtering

This is a technique of sampling object characteristics at a high resolution and displaying


results at a lower resolution.

ii. antialiasing by area sampling or prefiltering

An alternative to super sampling is to determine pixel intensity by calculating areas of overlap of


each pixel with the objects to be displayed antialiasing by computing overlaps areas is referred to
as area sampling or prefiltering

iii. antialiasing by pixel phasing

Raster objects can be antialiased by shifting the display location of pixel areas. This is applied by
“micro positioning” the electron beam in relation to object geometry
(18 Marks)

Page 4 of 8
Quiz 2

a) Digitize a line from (10,12) to (15,15) on a raster screen using Bresenham’s straight
line algorithm. [8]

Answer:
The line has a slope of 0.6 with Δx=5, Δy=3
The initial decision parameter has the valueP0=2Δy-Δx=6-5=1
And the increments for calculating successive decision parameters are2Δy-2Δx=6-10=-4
We plot the point (x0.y0) = (10,12), and determine successive pixel positions along the line
path from the decision parameter as

b) Explain the Bresenham’s line drawing algorithm with example of its implementation.
[20]

Answer:
BRESENHAM’S LINE ALGORITHM
1. Input the two line endpoints and store the left end point in (x0,y0)
2. load (x0,y0) into frame buffer, ie. Plot the first point.
3. Calculate the constants Δx, Δy, 2Δy and obtain the starting value for the decision
parameter as P0 = 2Δy-Δx
4. At each xkalong 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. Perform step4 Δx times.
Implementation of Bresenham Line drawing Algorithm
voidlineBres (int xa,intya,intxb, int yb)
{
int dx = abs( xa – xb) , dy = abs (ya - yb);
int p = 2 * dy – dx;
inttwoDy = 2 * dy, twoDyDx = 2 *(dy - dx);
int x , y, xEnd; /* Determine which point to use as start, which as end * /
if (xa> x b )

Page 5 of 8
{
x = xb;
y = yb;
xEnd = xa;
}
else
{
x = xa;
y = ya;
xEnd = xb;
}
setPixel(x,y);
while(x<xEnd)
{
x++;
if (p<0) p+=twoDy;
else
{
y++;
p+=twoDyDx;
}
setPixel(x,y);
}
}

Example : Consider the line with endpoints (20,10) to (30,18)


The line has the slope m= (18-10)/(30-20)=8/10=0.8
Δx = 10Δy=8
The initial decision parameter has the value p0 = 2Δy- Δx = 6
and the increments for calculating successive decision parameters are
2Δy=16 2Δy-2 Δx= -4
We plot the initial point (x0,y0) = (20,10) and determine successive pixel positions along
the
line path from the decision parameter as

Page 6 of 8
RESULT

c) Explain the midpoint circle drawing algorithm. Assume 10 cm as the radius and
coordinate origin as the centre of the circle [20]

Answer
Given a circle radius r=10
The circle octant in the first quadrant from x=0 to x=y.
The initial value of the decision parameter is
P0=1-r = - 9
For the circle centred on the coordinate origin, the initial point is
(X0, y0)=(0, 10)
and initial increment terms for calculating the decision parameters are
2x0=0, 2y0=20
Successive midpoint decision parameter values and the corresponding coordinate positions
along the circle path are listed in the following table.

Implementation of Midpoint Circle Algorithm


voidcircleMidpoint (int xCenter, int yCenter, int radius)
{
int x = 0; int y = radius;
int p = 1 - radius;
voidcirclePlotPoints (int, int, int, int); /* Plot first set of points */
irclePlotPoints (xCenter, yCenter, x, y);
while (x < y)
{

Page 7 of 8
x++ ;
if (p < 0) p +=2*x +1;
else
{
y--; p +=2* (x - Y) + 1;
}
circlePlotPoints(xCenter, yCenter, x, y)
}
}
voidcirclePlotPolnts (int xCenter, int yCenter, int x, int y)
{
setpixel (xCenter + x, yCenter + y ) ;
setpixel (xCenter - x. yCenter + y);
setpixel (xCenter + x, yCenter - y);
setpixel (xCenter - x, yCenter - y ) ;
setpixel (xCenter + y, yCenter + x);
setpixel (xCenter - y , yCenter + x);
setpixel (xCenter t y , yCenter - x);
setpixel (xCenter - y , yCenter - x);
}
(48 Marks)

Page 8 of 8

You might also like