Computer Graphics Exercise
Computer Graphics Exercise
The boundary of a circle can be represented discretely by using few methods and
algorithms, namely the Middle Point Circle Algorithm and Bresenhams 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
o
o , y
Po=1r
(for r is an integer)
2 x o =40 , 2 y o=50
At each
xk
parameter,
If
pk <0
and,
pk+1 =p k + 2 x k +1+1
Otherwise, if
pk >0
where
2 x k +1=2 x k +2
and
2 y k+1=2 y k +2
x=x+ x c , y= y + y c
x
( c , y c )
x
( , y )
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
a3
b2
Cross product
v bc
v pa
a2 b3
v pb
a3
b1 -
v pc
a1 b3
v ab
v bc
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
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( , )
( 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
m1 =
x 1+ x
2
m2 =
y1+y
2
15+ 42
2
= 13.5
17+ 144
2
= 80.5