0% found this document useful (0 votes)
78 views10 pages

Assignment 2

The document contains questions and answers related to computer graphics concepts. It discusses the midpoint ellipse algorithm, drawing a circle using pixel coordinates, boundary filling algorithms, scan conversion of polygons, and generating a homogeneous transformation matrix for a composite transformation involving translation, scaling, and rotation.

Uploaded by

Baljeet Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
78 views10 pages

Assignment 2

The document contains questions and answers related to computer graphics concepts. It discusses the midpoint ellipse algorithm, drawing a circle using pixel coordinates, boundary filling algorithms, scan conversion of polygons, and generating a homogeneous transformation matrix for a composite transformation involving translation, scaling, and rotation.

Uploaded by

Baljeet Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 10

ASSIGNMENT NO 2 Computer Graphics CSE (405)

Submitted to : By: Miss Shamli Submitted Baljeet Kaur Roll no 15

Section B1802

Ques :Explain the mid point algorithm for ellipse .


Ans: Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics. This method is modified from Bresenhams algorithm. The advantage of this modified method is that only addition operations are required in the program loops. This leads to simple and fast implementation in all processors.

Mid Point ellipse midpoint algorithm:


1. Get parameters a, b, h, k for center coordinate h and k and major&minor axis lengths 2aand

2b.

2. Calculate the initial decision parameter value in the first region:

.
3. Use the formulas above to iterate pxk+1 until b2x>a2y. 4. Rename the current (xk,yk) as (x0,y0) and calculate the initial decision parameter value in the

2nd region: .
5. Use the formulas above to iterate pyk+1 until y <= 0.

6. For both regions plot the other three symmetry points. 7 Shift to center at h, k.

Ques2- Draw the circle with pixel as (30,50) respect to origin (0, 0) where radius of circle is 25..
Solution:Selected pixel positions (solidcircles) along a circle path withradius r = 25 centered on

the origin, using the midpoint circle algorithm.Open circles show the symmetry positions in the first quadrant with the given pixel (30,50)

Ques 3 Explain the concept of boundary filling in computer graphics? Ans:


Boundary fill Area-filling algorithms starts at a point known to be inside a figure and starts filling in the figure outward from the point. Using these algorithms a graphic artist may sketch the outline of a figure and then select a color or pattern with which to fill it. The actual filling process begins when a point inside thefigure is selected. These routines are like the paint-scan function seen in common interactive paint packages. The first such method that we will discuss is called the boundary-fill algorithm. The boundary-fill method requires the coordinates of a starting point, a fill color, and a boundary color as arguments.

Boundary fill algorithm:


The Boundary fill algorithm performs the following steps: Check the pixel for boundary color Check the pixel for fill color Set the pixel in fill color Run the process for neighbors The pseudo code for Boundary fill algorithm can be written as: boundaryFill (x, y, fillColor , boundaryColor) if ((x < 0) || (x >= width)) return if ((y < 0) || (y >= height))

return current = GetPixel(x, y) if ((current != boundaryColor) && (current != fillColor)) setPixel(fillColor, x, y) boundaryFill (x+1, y, fillColor, boundaryColor) boundaryFill (x, y+1, fillColor, boundaryColor) boundaryFill (x-1, y, fillColor, boundaryColor) boundaryFill (x, y-1, fillColor, boundaryColor)

Ques4 Give the rules for scan conversion of polygon region with the help of a example
Ans: 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

There are many ways to draw polygons. All have their uses. Some are fast, others very slow. The most popular method, used in practically every game, rendering engine, and graphics package which handles polygons, is known as scan converting. (i)This method uses only integer maths, takes up very little memory, and is simple to understand. The algorithm can be adapted to handle flat or gourad shaded, textured and bump mapped polygons. (ii)It is an approximate method. You will never be able to draw a totally perfect polygon with smooth edges on a normal screen, because of the fact that the picture is divided up into pixels. It is possible to make the edges look better, but the edges will nevertheless look jaggy.

On a pixelated screen, a small polygon like this will end up with nasty edges when viewed close up. (iii)The method works by taking the polygon a line at a time, processing all the edges, then filling in the surface. If you haven't already, take a look at the page about drawing lines. You will find this very helpful. (iv)A single scan conversion is the process of converting a polygon edge into data which can be used by the polygon filling routine. The process is essentially a single case of the line drawing algorithm. A polygon edge is calculated as if it were a line, but the line is not drawn to the screen. Instead the information is saved in a buffer for use later. So the line algorithm travels down an edge, calculating the X-coordinate of the pixel which lies closest to the line for each Y-coordinate.

Ques5:Find the transformation that scales (with respect to origin) by a) a units in the X direction, Ans:In this translation transformation is used in the X direction A translation is applied to an
object by repositioning it along a straight-line pathfrom one coordinate location to another

b) b units in the Y direction, Ans: In this scaling transformation is used in the X direction c)simultaneously a units in the X direction and b units in the Y direction Ans: In This Shearing transformation is used in the X direction and b units in the Y direction

Ques6

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=6, y=4, tx=8, ty=4, s=3, and =-30.


two-dimensional transformation, representing a combination of translations, rotations, and scalings, can be
X RSxx RSxy RSyy 0 =

Solution: A general

Y = RSyx 1 0

Sx cos Sx sin 0

-Sy sin Sy cos 0

Xc(1-Sx cos )+ YcSy sin + tx

Yc(1-Sy cos ) - XcSx sin + ty

x=6, y=4, tx=8, ty=4, s=3, and =-30. T (Tx,Ty). R(Xc,Yc, ). S(Xc,Yc,Sx,Sy)

Sx cos 30 Sx sin 30 0

-S4 sin 30 Sy cos 30 0

6c(1-Sx cos 30 )+ 4cSy sin 30 + 8 4c(1-Sy cos 30 ) - 6cSx sin 30 + 4 1

These unit vectors are transformed by the rotatign submatrix, Rxx,Rxy,) is converted to a unit vector along the x axis and (Ryx, Ryy) is transformed

unit vector along they axis of the coordinate system: As

T(tx,ty).R(x,y,) cos sin 0 -sin cos 0 x(1- cos +y sin + tx) y(1- cos 1 -x sin + ty )

T(8,4).R(6,4,-30)

cos 30 -sin 30 sin 30 0 cos 30 0

6(1- cos 30 + 4sin 30 +8) 4(1- cos 30 - 6 sin 30 +4) 1 and

Here, orthogonal unit vectors in the upper-left 2-by-2 submatrix are cos ,- sin
sin , cos and cos , 0 cos sin , = 1 1 1 0 1

sin , cos 0 0 0

Cos sin cos

Sin Sin cos

0 0

1 = 0

You might also like