B190230a-Cs411 Assign 2
B190230a-Cs411 Assign 2
B190230a-Cs411 Assign 2
NAME MAVIS T.
SURNAME MUNDENDA
LEVEL 4.2
PROGRAMME I.T
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]
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
The ratio of vertical points to the horizontal points necessary to produce length of lines in both
directions of the screen
c) Differentiate
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
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);
}
}
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.
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