Tuesday, October 21, 2014

Some graphical mathematical problem - solutions


*  What pixels will be marked in drawing a circle center (100,90) and radius 10? using Bresenham's algorithm

Ans:

Take x=0,y=r=10,d=3-2r=3-2*10=-17

Decision variable (d)
x
y
Point with Center (0,0)
Point with Center (100,90)

0
10
(0,10)
(100,100)
-17
1
10
(1,10)
(101,100)
-11
2
10
(2,10)
(102,100)
-1
3
10
(3,10)
(103,100)
13
4
9
(4,9)
(104,99)
-5
5
9
(5,9)
(105,99)
17
6
8
(6,8)
(106,98)
11
7
7
(7,7)
(107,97)





*    Which points will be scan converted by direct method for a line whose end points are (2,3) and (8,5)

Ans: 

dx=X2-X1=8-2=6 , dy=Y2-Y1=5-3=2 m=dy/dx=2/6=1/3, c=Y1-mX1=3-2/3=7/3 (since y=mx+c)

Since |m|=1/3<1, so we sample dx=1 and calculate y correspondingly
The various point plotted are given below:

X
Y=mX+c
Point Plotted
2
3.00
(2,3)
3
3.33
(3,3)
4
3.66
(4,4)
5
4.00
(5,4)
6
4.33
(6,4)
7
4.66
(7,5)
8
5.00
(8,5)





*    Calculate the points using DDA Algorithm that would be plotted for a line whose end points are (12,10) and (20,20)

Ans :
            Slope of the line m=dy/dx=(20-10)/(20-12)=5/4=1.25
            Since |m|>1 and we start from left endpoint, we sample at dy=1 and calculate corresponding x using formula  Xk+1=Xk+1/m
The following table gives the points to be plotted on the screen for the line. The first point plotted is (12,10).

Xk+1=Xk+1/m
Y
Point Plotted (X,Y)
12.8
11
(13,11)
13.6
12
(14,12)
14.4
13
(14,13)
15.2
14
(15,14)
16.0
15
(16,15)
16.8
16
(17,16)
17.6
17
(18,17)
18.4
18
(18,18)
19.2
19
(19,19)
20.0
20
(20,20)





*    Indicate which raster locations would be chosen by Bresenham’s Line algorithm, when scan converting a line from pixel coordinate (1,1) to pixel coordinate (8,5)

Ans:
            The two end points are (1,1) and (8,5)
            So  dx=8-1=7 and dy=5-1=4 and m=dy/dx=4/7<1
            The initial decision parameter is P0=2dy-dx=8-7=1 and 2dy=8, 2dy-2dx=-6
            We plot the initial point (1,1) and determine successive pixel position alone the line as follows:

K
Decision Parameter
Point to be plotted  Xk+1,Yk+1
0
1
(2,2)
1
-5
(3,2)
2
3
(4,3)
3
-3
(5,3)
4
5
(6,4)
5
-1
(7,4)
6
7
(8,5)

So the above points are scan convert a line between (1,1) and (8,5)





*    Using Mid point Circle algorithm , find out the screen coordinates of the circumference of a circle whose center is (0,0) and radius is 10 units.

Ans:
            Radius of the circle =10, Initial decision parameter P=1-r=1-10=-9
            As the circle is centered at (0,0), the initial point plotted is (0,r) =(0,10)
            Successive screen points are circulated using midpoint method as follows:

X
Y
Decision parameter P
Point to be plotted
0
10
-9
(1,10)
1
10
-6
(2,10)
2
10
-1
(3,10)
3
10
6
(4,9)
4
9
-3
(5,9)
5
9
8
(6,8)
6
8
5
(7,7)

            As we reach the condition x=y, we generate the rest of pixel positions using 8 way symmetric of circle.  

1 comment: