334csm Chapter3 Exercise Solution
334csm Chapter3 Exercise Solution
EXERCISE 1:
Consider the line from (0,0) to (3,3). Use DDA algorithm to find the co-ordinates of this line.
SOLUTION:
dx = 3-0 = 3
dy = 3-0 = 3
Steps = Max(dx,dy) = Max(3,3) = 3
Xinc = float(dx) / float(steps) = 3/3 = 1
Yinc = float(dy) / float(steps) = 3/3 = 1
Initially X=0 Y=0
For (K=0; K<steps; K++)
K X = X+Xinc Y = Y + Yinc Value Computed
0 0+1= 1 0+1=1 1, 1
1 1+1=2 1+1=2 2, 2
2 2+1=3 2+1=3 3, 3
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8
EXERCISE 2:
Consider the line from (6,9) to (11,12). Use DDA algorithm to find the co-ordinates of this line.
SOLUTION:
17
16
8
15
7
14
13
12
11
10
9
6 7 8 9 10 11 12 13
EXERCISE 3:
Apply Bresenham’s Line Drawing algorithm to find the points of the line between the end
points, (2,2) and (10,10).
1. Plot (2,2)
2. Δx = 10 – 2 = 8 Δy = 10 – 2 = 8
2Δy = 2 * 8 = 16
2Δy-2Δx = 16 – 16 = 0
3. P0 = 2Δy- Δx
= 16- 8 = 8
If Pk < 0 Plot (Xk+1,Yk) and Pk+ 1 = Pk + 2Δy
else Plot (Xk+1,Yk+1) and Pk+ 1 = Pk + 2Δy - 2Δx
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10
EXERCISE 4:
Digitize a line from (10,12) to (15,15) on a raster screen using Bresenhams straight line
algorithm.
1. Plot (10,12)
2. Δx = 15 – 10 = 5 Δy = 15 – 12 = 3
2Δy = 2 * 3 = 6
2Δy-2Δx = 6 – 10 = -4
3. P0 = 2Δy- Δx
= 6-5 = 1
If Pk < 0 Plot (Xk+1,Yk) and Pk+ 1 = Pk + 2Δy
else Plot (Xk+1,Yk+1) and Pk+ 1 = Pk + 2Δy - 2Δx
21
20
1
19
18
17
16
15
14
13
12
11
10
10 11 12 13 14 15 16 17 18 19 20 21
EXERCISE 5:
Given the circle radius r=20, Demonstrate the midpoint circle algorithm by determining the
circle points along the circle octant in the first quadrant from x=0 to x=y.
SOLUTION:
For the circle centred on the origin, the initial point is (x0, y0) = (0,r) (0, 20), and the initial
increment term for calculating the decision parameters are
Successive decision parameters values and positions along the circle path are calculated using
midpoint algorithm as follows:
20
19
18
17
16
15
14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
EXERCISE 6: Given the circle radius r=7, Demonstrate the midpoint circle algorithm by
determining the circle points along all the octant(Complete circle).
SOLUTION:
Value of the decision parameter is P0 = 1 – r
P0= 1-7 = -6
For the circle centered on the origin, the initial point is (x0, y0) = (0,r) (0, 7), and the initial
increment term for calculating the decision parameters are
Successive decision parameters values and positions along the circle path are calculated using
midpoint algorithm as follows:
20
19
18
17
16
15
14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
EXERCISE 7:
If (x,y)=(3,6) is a co-ordinate of a circle in an octant of first quadrant, find the other circle points
in remaining seven octants using the Symmetric property of circle.
SOLUTION:
(x,y)=(3,6)
Other points are (6,3), (3,-6) , (6,-3), (-6, -3), (-3,-6), (-3,6), (-6,3)
EXERCISE 8:
In Midpoint Circle Generation algorithm If Decision parameter Po at the start position is (0,r).
Prove Po = 1-r.
Po = (0,r) x = 0, y= r
Po = fcirc 0+1, r - 1
2
= fcirc 1, r - 1
2
=12+r–1 2
– r2
2
= 1 + r 2 + 1 – 2 r * 1 – r2
4 2
= 1 + r2 + 1 – 2r – r2
4 2
=1+1–r
4
= 5–r
4
=1-r