You are on page 1of 6

Submitted To: Shamli Mam

Submitted By: Krishan Kumar

RB1803 B53

1 Explain the mid point algorithm for circle.


Answer:- 1. Input radius r and circle center (xc,yc) and obtain the first point on
the circumference of a circle centered on the origin as

(x0,y0) = (0,r)

2. Calculate the initial value of the decision parameter as

p0 = 5/4 – r

3. At each x[k] position, starting at k = 0, perform the following test: If p[k] <
0, the next point along the circle centered on (0,0) is (x[k+1], y[k]) and

p[k+1] = p[k] + 2x[k+1] + 1

Otherwise, the next point along the circle is (x[k+1], y[k-1]) and

p[k+1] = p[k] + 2x[k+1] + 1 – 2y[k+1]

where 2x[k+1] = 2x[k] + 2 and 2y[k+1] = 2y[k] – 2

4. Determine symmetry points in the other seven octants.

5. Move each calculated pixel position (x,y) onto the circular path centered on
(xc,yc)

and plot the coordinate values:

x = x + xc, y = y + yc

6. Repeat steps 3 through 5 until x >= y.

3 Explain the concept of flood filling in computer graphics?


Answer: flood filling:
• Used when an area defined with multiple color boundaries
• Start at a point inside a region
• Replace a specified interior color (old color) with fill color
• Used in interactive paint systems.
• The user specify a seed by pointing to the interior of the region to initiate a flood
operation
Fill the 4-connected or 8-connected region until all interior points being replaced
void FloodFill4(int x, int y, color newcolor, color oldColor)
{
if(ReadPixel(x, y) == oldColor)
{
FloodFill4(x+1, y, newcolor, oldColor);
FloodFill4(x-1, y, newcolor, oldColor);
FloodFill4(x, y+1, newcolor, oldColor);
FloodFill4(x, y-1, newcolor, oldColor);
}
}

PART B

4 Give the rules for scan conversion of polygon region with the help of a example
Answer:-
The job of scan conversion is to shade pixels lying within a closed polygon, and to do so efficiently. The fill
colour will in general depend on the lighting, texture, and visibility of the polygon being scan-converted.
These will be ignored for the time being.

Let's assume that the polygon is closed and has ordered edges.
The scan conversion algorithm then works as follows:

• intersect each scanline with all edges


• sort intersections in x
• calculate parity of intersections to determine in/out
• fill the 'in' pixels
• Special cases:
• horizontal edges can be excluded
• vertices lying on scanlines
• change in sign of slope: count twice
• no change: shorten edge by one scanline

5 Perform a 45 degree rotation of triangle A(0,0),B(1,1),C(5,2).


a)about the origin and
b)about p(-1,-1).

Answer:- The matrix of rotation is:-

R= cos 45 -sin 45 0 = 0.707 -0.707 0

Sin 45 cos 45 0 0.707 0.707 0

0 0 1 0 0 1

A’B’C’= R45 DEGREE (ABC) =

0.707 -0.707 0 0 1 5

0.707 0.707 0 0 1 2

0 0 1 1 1 1

0 0 2.121

= 0 2 4.909

1 1 1

So A’=(0,0), B’=(0,2) C’=(2.121,4.949)


(II) About point (-1,-1)
Answer:- R 45 DEGREE= T INVERSE*(R45 DEGREE)*T

1 0 -1 0.707 0.707 0 1 0 1

0 1 -1 0.707 0.707 0 0 1 1

1 1 1 0 0 1 1 1 1

= 0.707 - 0.707 -1
0.707 0.707 0.414
0 0 1

A’B’C’= R 45 DEGREE (ABC)

0.707 - 0.707 -1 0 1 5
0.707 0.707 0.414 0 1 2
0 0 1 1 1 1

A’= (-1, 1.414)


B’= (-1, 1.828,)
C’= (3.242, 5.36)

6. Generate the homogeneous matrix for the composite transformation by applying the
translation (tx,ty), followed by uniform scaling (s), and then followed by rotation (θ), on the
object (x,y) in a 2D homogeneous coordinate system. Further, apply the transformation
taking x=5, y=3, tx=7, ty=3, s=2, and θ=-30.
Answer:- Here ,we are required to first apply translation and then scaling and then we need to
rotate by angle θ .hence the reqd matrix will be a composite matrix . The required homogeneous
matrix for the composite transformation will be the product of four matrices and is given by

X’ cos Ѳ - sin Ѳ 0 s 0 0 1
0 tx X

Y’ = sin Ѳ cos Ѳ 0 0 s 0 0
1 ty Y

1 0 0 1 0 0 1 0
0 1 1

cos Ѳ -sin Ѳ 0 s 0 s*tx X

= sin Ѳ cos Ѳ 0 0 s s*ty Y

0 0 1 0 0 1 1

s.cos Ѳ -s.sin Ѳ s.tx.cos Ѳ – s.ty.sin Ѳ X

= s. sin Ѳ s.cos Ѳ s.tx.sin Ѳ + s.ty.cos Ѳ Y

0 0 1
1

X’ s.cos Ѳ .X – s.sin Ѳ.Y + s.tx.cos Ѳ – s.ty.sin


Ѳ

Y’ = s.sin Ѳ .X + s.cos Ѳ.Y + s.tx.sin Ѳ + s.ty.cos


Ѳ

1 1
X’ 2.cos 150 – 6.sin 90 + 14.cos 30 – 6.sin 30

Y’ = 2.sin 150 + 2.cos 90 + 6.sin 30 + 6.cos 30

1 1

X’=25

Y’=-2

You might also like