Written Assignment 2 NAME: Saiful Emran Bin Abdul Muttalib MATRIC NO: 46000 Question 1 Explain how you would adapt the rasterisation algorithm you have learned in the lecture that discretises lines to discretely represent the boundary of a circle. What pixels would be filled in to represent a circle centered at (20, 20) with a radius of 5?
The boundary of a circle can be represented discretely by using few methods and algorithms, namely the Middle Point Circle Algorithm and Bresenham’s Algorithm. In both algorithm, it takes advantage of the symmetry of a circle; the shape of the circle is similar in each quadrant. Therefore, computation can be reduced as we only calculate the pixel position for the first quadrant. The second quadrant can be obtained by noting that the two circle sections are symmetric with respect to the y axis. Circle sections of the third and forth quadrant can be obtained from sections in the first and second quadrants by considering the symmetry about the x axis.
By using Middle Point Circle Algorithm, we determine the closest pixel position to the specified circle path at each step. For a given radius, r = 5, and the circle
center position,
x 20,2 (¿ ¿ c , y c )=¿ 0), firstly we obtain the first point on the ¿
circumference of the circle centered on the origin as
x ¿ o ¿ o , y¿ ¿ ¿
Next, we calculate the initial value of the decision parameter by using,
Po=1−r
(for r is an integer)
Initial increment terms for calculating the decision parameters are
2 x o =40 , 2 y o=50
At each
xk
position starting at k=0, we perform the test using the decision
parameter,
If
pk <0
,the next point along the circle is
x ¿ k ¿ ¿
and,
pk+1 =p k + 2 x k +1+1
Otherwise, if
pk >0
the next point along the
pk+1 =p k +2 x k +1+1−2 y k+1
where
2 x k +1=2 x k +2
and
2 y k+1=2 y k +2
Then, we determine symmetry points in the other seven half-quadrants. Next, we move each calculated pixel position
circle center position
x=x+ x c , y= y + y c
x (¿ ¿ c , y c ) ¿
x (¿ ¿ , y ) ¿
onto the circular path centered on the
. Coordinate values can be plotted by,
The decision parameter test is done to plot another coordinate values. This steps are taken until value of
x≥ y .
K 0 1 2
Xk+1,yk+1 (21,25) (22,24) (23,23)
Question 2 Consider a triangle with corners at (2,2,3) (3,3,4), (3,1,3). a. What is the normal vector to this triangle? a = ( a1 , a2
, a3
) = (2, 2, 3)
b = ( b1 , b2 , b3
) = (3, 3, 4)
c = ( c 1 , c 2 , c3
) = (3, 1, 3)
v ab
= ( b2
-
a1 ,
b2
-
a2 ,
b3
-
a3 ) = (1, 1, 1)
v bc
= ( c1
-
b1 ,
c2 -
b2 ,
c3
-
b3 ) = (0, -2, -1)
a3
b2
Cross product
v bc
x
v pa
=
a2 b3
-
v pb
=
a3
b1 -
v pc
=
a1 b3
-
∴
v ab
v bc
x
v ab
a1 b3
= (-2)(1) – (-1)(1) = -1 = (-1)(1) – (0)(1) = -1
a2 b1 = s(0)(1) – (-2)(1) = 2 = (-1, -1, 2) x -1
= (1, 1, -2)
b. What is an equation for the plane that this triangle lies in?
A= (2,2,3),
⃗n =(1,1,−2)
⃗n [ ( x , y , z )− ( 2,2,3 ) ]=0
( 1,1,−2 ) ∙ [ ( x , y , z )−( 2,2,3 ) ]=0 ( x−2 ) + ( y−2 ) −2 ( z−3 )=0
Question 3 Based on the Liang-Barsky line clipping algorithm, consider the following line which we need to clip on a rectangular viewport with the corner coordinates as [(10, -20), (202, 130)]. The endpoints of the line are of coordinates (-15, 17) and (42, 144). a. What is the parametric equation of the line? Write it in the form ( , ) = ( , ) + t1( , ) Where
and
( , ) = ( , ) + t2( , )
t1 and t2 values are the approximation ratios range within [0, 1]
( x ) = ( -15 ) + t1 ( 27 ) ( y ) = ( 42 ) + t2 ( 161 )
b. What are the coordinates of the new endpoints of the visible segment? (42,144 )
(202,13 0)
(10,13 0)
(-
(202,20)
(10,2
Endpoint visible segment
m1 =
x 1+ x 2
m2 =
y1+y 2
2
2
=
−15+ 42 2
= 13.5
=
17+ 144 2
= 80.5
= (10, 80.5) / (10 , 81) = (13.5 , 130) / (14, 130)
c. What is the disadvantage of Liang-Barsky algorithm to Cohen Sutherland line clipping algorithm The Liang-Barsky algorithm is more efficient than Cohen Sutherland, but Cohen Sutherland does trivial accepts and rejects more faster so it should be considered instead if most of the lines needed to clip would be completely in or out the window.