Q.) Explain Scan Line Algorithm of Polygon Clipping
Q.) Explain Scan Line Algorithm of Polygon Clipping
Ans For each scan line crossing a polygon, the area-fill algorithm locates
the intersection points of the scan line with the polygon edges.
These intersection points are then sorted from left to right, and the
corresponding frame-buffer positions between each intersection pair are set
to the specified fill color.
Scan line algorithm works by intersecting scan line with polygon edges
and fills the polygon between pairs of intersections. The following steps
depict how this algorithm works.
Step 1 : Find out the Ymin and Ymax from the given polygon.
Step 2 : ScanLine intersects with each edge of the polygon from Ymin to
Ymax. Name each intersection point of the polygon. As per the Fig. 2.21
shown, they are named as p0, p1, p2, p3.
Step 3 : Sort the intersection point in the increasing order of X coordinate
i.e. (p0, p1), (p1, p2), and (p2, p3).
Step 4 : Fill all those pair of coordinates that are inside polygons and
ignore the alternate pairs.
Q.]Explain midpoint subdivision line clipping algorithm. 4 M
Ans Step 1: Scan two end points for the line P1(x1, y1) and P2(x2, y2).
Step 2: Scan corners for the window as (Wx1, Wy1) and (Wx2, Wy2).
Step 3: Assign the region codes for endpoints P1 and P2 by initializing code
with
0000.
Bit 1 - if (x < Wx1)
Bit 2 - if (x > Wx2)
Bit 3 - if (y < Wy1)
Bit 4 - if (y > Wy2)
Step 4: Check for visibility of line P1, P2.
If region codes for both end points are zero then the line is visible, draw it
and jump to step 6.
If region codes for end points are not zero and the logical Anding
operation of them is also not zero then the line is invisible, reject it and jump
to step 6.
If region codes for end points does not satisfies the condition in 4 (i)
and 4 (ii) then line is partly visible.
Step5: Find midpoint of line and divide it into two equal line segments and
repeat
steps 3 through 5 for both subdivided line segments until you get completely
visible and completely invisible line segments.
Step 6: Exit.
Q.]Explain Cyrusblek line clipping algorithm. 6 M
Ans Cyrus Beck Line Clipping algorithm:
Cyrus Beck Line Clipping algorithm is used to clip 2D/3D lines against
convex polygon/polyhedron.
• Cyrus Beck Line clipping algorithm is actually, a parametric line-
clipping
algorithm.
• The term parametric means that we require finding the value of the
parameter t in the parametric representation of the line segment for the
point
at that the segment intersects the clipping edge.
Algorithm Cyrus Beck Line Clipping Algorithm:
Step 1 : Read end points of line P1 and P2.
Step 2 : Read vertex coordinates of clipping window.
Step 3 : Calculate D = P2 – P1.
Step 4 : Assign boundary point b with particular edge.
Step 5 : Find inner normal vector for corresponding edge.
Step 6 : Calculate D.n and W = P1 – b
Step 7 : If D.n > 0
tL = – (W.n)/(D.n)
else
tU = – (W.n)/(D.n)
end if
Step 8 : Repeat steps 4 through 7 for each edge of clipping window.
Step 9 : Find maximum lower limit and minimum upper limit.
Step 10 : If maximum lower limit and minimum upper limit do not satisfy
condition 0 ≤ t ≤ 1 then
ignore line.
Step 11 : Calculate intersection points by substituting values of maximum
lower limit and minimum upper limit in parametric equation of line P1P2.
Step 12 : Draw line segment P(tL) to P(tU).
Step 13 : Stop
Q.]Describe Sutherland-Hodgeman algorithm for polygon clipping.
In Sutherland-Hodgeman, a polygon is clipped by processing the polygon
boundary as a whole against each window edge. Clipping window must be
convex.
This could be accomplished by processing all polygon vertices against each
clip rectangle boundary in turn beginning with the original set of polygon
vertices, first clip the polygon against the left rectangle boundary to produce a
new sequence of vertices.
The new set of vertices could then be successively passed to a right boundary
clipper, a top boundary clipper and a bottom boundary clipper.
At each step a new set of polygon vertices us generated and passed to the
next window boundary clipper. This is the logic used in Sutherland-Hodgeman
algorithm.
Eg:Assume that we're clipping a polygon’s edge with vertices at (x1, y1) and
(x2, y2) against a clip window with vertices at (xmin, ymin) and (xmax, ymax).
1. The location (IX, IY) of the intersection of the edge with the left side of the
window is:
(i) IX = xmin
(ii) IY = slope*(xmin – x1) + y1, where the slope = (y2 – y1)/(x2 – x1).
2.The location of intersection of the edge with the right side of the window is:
(i) IX = xmax
(ii) IY = slope*(xmax – x1) + y1, where the slope = (y2 – y1)/(x2 – x1)
3.The intersection of the polygon's edge with the top side of the window is:
(i) IX = x1 + (ymax – y1) / slope
(ii) IY = ymax
4. Finally, the intersection of the edge with the bottom side of the window is:
(i) IX = x1 + (ymin – y1) / slope
(ii) IY = ymin
Algorithm for Sutherland-Hodgeman Polygon Clipping:
Step 1: Read co-ordinates of all vertices of the polygon.
Step 2: Read co-ordinates of the clipping window.
Step 3: Consider the left edge of window.
Step 4: Compare vertices of each of polygon, individually with the clipping
plane.
Step 5: Save the resulting intersections and vertices in the new list of vertices
according to four possible relationships between the edge and the clipping
boundary.
Step 6: Repeat the steps 4 and 5 for remaining edges of clipping window. Each
time resultant list of vertices is successively passed to process next edge of
clipping window.
Step 7: Stop.
Q.]Explain and write steps for DDA line drawing algorithm. 4 M
This algorithm generates a line from differential equations of line and
hence the name DDA.
DDA algorithm is an incremental scan conversion method.
A DDA is hardware or software used for linear interpolation of
variablesover an interval between start and end point.
DDAs are used for rasterization of lines, triangles and polygons.
DDA method is referred by this name because this method is very
similar
to the numerical differential equations. The DDA is a mechanical device
that solves differential equations by numerical methods.
Algorithm:
Steps 1: Read the end points of line (x1,y1) and (x2,y2).
Steps 2: dx = abs (x2 – x1) and
dy = abs (y2 – y1)
Step 3: if dx ≥ dy then
length = dx
else
length = dy
end if
Step 4: dx = (x2 – x1)/length
Step 5: dy = (y2 – y1)/length
Step 6: x= x1 + 0.5 * sign (dx)
y= y1 + 0.5 * sign (dy)
Step 7: i = 1
while (i ≤ length)
{
plot (integer (x), integer (y))
x = x + dx
y = y + dy
i=i+1
}
Step 8: End
Q.]Write down Cohen-Sutherland Line clipping algorithm. 4M
Step 1: Scan end points for the line P1(x1, y1) and P2(x2, y2)
Step 2: Scan corners for the window as (Wx1, Wy1) and (Wx2, Wy2)
Step 3: Assign the region codes for endpoints P1 and P2 by
Bit 1 - if (x < Wx1)
Bit 2 - if (x < Wx2)
Bit 3 - if (x < Wy2)
Bit 4 - if (x < Wy1)
Step 4: Check for visibility of line P1, P2
If region codes for both end points are zero then the line is visible, draw it
and jump to step 9.
If region codes for end points are not zero and the logical and operation of
them is also not zero then the line is invisible, reject it and jump to step 9.
If region codes for end points does not satisfies the condition in 4(i) and 4(ii)
then line is partly visible.
Step 5: Determine the intersecting edge of the clipping window by inspecting
the region codes for endpoints.
If region codes for both the end points are non-zero, find intersection points
P1 and P2 with boundary edges of clipping window with respect to point P1 and
P2.
If region code for any one end point is non zero then find intersection point
P1 or P2 with the boundary edge of the clipping window with respect to it.
Step 6: Divide the line segments by considering intersection points.
Step 7: Reject the line segment if any of the end point of it appear outside the
window.
Step 8: Draw the remaining line.
Step 9: Exit
Q.]Write DDA Arc generation algorithm. 4 M
1. Read the centre of curvature, say(x0,y0)
2. Read the arc angle, say Ɵ
3. Read the starting point of the arc, say(x,y)
4. Calculate dƟ
dƟ=min(0.01,1/3.2*(|x-x0|+|y-y0|)))
5. Initialize angle = 0
6. while (angle < Ɵ)
do
{
Plot(x,y)
x=x-(y-y0) *dƟ
y=y-(x-x0) *dƟ
Angle =Angle + dƟ
}
7. stop
Q.]Explain 2D transformations with its types. 4 M
A transformation is a function that maps every position (x, y) into a new
position (x', y'). Instead of applying the transformation function to every point
in every line that makes up the object, we simply apply the function to the
object vertices and then draw new lines between the resulting new endpoints.
Basic Transformations:
1)Translation
2)Scaling
3)Rotation
1)Translation:
A translation is applied to an object by repositioning it along a straight-line
path from one coordinate location to another.
Translation refers to the shifting (moving) of a point to some other place,
whose distance with regard to the present point is known.
Translation can be defined as “the process of repositioning an object along a
straight line path from one co-ordinate location to new co-ordinate location.”
A translation moves an object to a different position on the screen. You can
translate a point in 2D by adding translation coordinate (tx, ty) to the original
coordinate (X, Y) to get the new coordinate (X', Y')
2)Rotation
Rotation as the name suggests is to rotate a point about an axis.
The axis can be any of the co-ordinates or simply any other
specified line also.
In rotation, we rotate the object at particular angle θ (theta) from
its origin. From the following figure, we can see that the point
P(X, Y) is located at angle φ from the horizontal X coordinate
with distance r from the origin.
Let us, suppose you want to rotate it at the angle θ. After rotating
it to a new location, you will get a new point P' (X', Y').
3)Scaling:
Scaling means to change the size of object. This change can either be positive
or negative.
To change the size of an object, scaling transformation is used. In the scaling
process, you either expand or compress the dimensions of the object.
Scaling can be achieved by multiplying the original co-ordinates of the object
with the scaling factor to get the desired result.
Q.]Explain Koch curve with diagram. 4 M
Koch Curve: - In Koch curve, begin at a line segment. Divide it into third
and replace the center by the two adjacent sides of an equilateral triangle as
shown below. This will give the curve which starts and ends at same place as
the original segment but is built of 4 equal length segments, with each 1/3rd
of the original length. So the new curve has 4/3 the length of original
segments. Repeat same process for each of the 4 segment which will give
curve more wiggles and its length become 16/9 times the original. Suppose
repeating the replacements indefinitely, since each repetition increases the
length by a factor of 4/3, the length of the curve will be infinite but it is folded
in lots of tiny
Q.]Explain character generation methods: i. Stroke ii. Starburst iii. Bitmap
1) STROKE METHOD
Stroke method is based on natural method of text written by human being. In
this method graph is drawing in the form of line by line.
Line drawing algorithm DDA follows this method for line drawing.
This method uses small line segments to generate a character. The small
series of line segments are drawn like a stroke of pen to form a character.
We can build our own stroke method character generator by calls to the line
drawing algorithm. Here it is necessary to decide which line segments are
needed for each character and then drawing these segments using line drawing
algorithm.
2)BITMAP METHOD
Bitmap method is a called dot-matrix method as the name suggests
thismethod use array of bits for generating a character. These dots are the points
for array whose size is fixed.
In bit matrix method when the dots is stored in the form of array the value 1
in array represent the characters i.e. where the dots appear we represent that
position with numerical value 1 and the value where dots are not present is
represented by 0 in array.
It is also called dot matrix because in this method characters are represented
by an array of dots in the matrix form. It is a two dimensional array having
columns and rows.
A 5x7 array is commonly used to represent characters. However 7x9 and 9x13
arrays are also used. Higher resolution devices such as inkjet printer or laser
printer may use character arrays that are over 100x100.
3) Starbust method:
In this method a fix pattern of line segments are used to generate characters.
Out of these 24 line segments, segments required to display for particular
character are highlighted. This method of character generation is called
starbust method because of its characteristic appearance
The starbust patterns for characters A and M. the patterns for particular
characters are stored in the form of 24 bit code, each bit representing one
line segment. The bit is set to one to highlight the line segment; otherwise
it is set to zero. For example, 24-bit code for Character A is 0011 0000
0011 1100 1110 0001 and for character M is 0000 0011 0000 1100 1111 0011.
This method of character generation has some disadvantages. They are
1. The 24-bits are required to represent a character. Hence more memory is
required.
2. Requires code conversion software to display character from its 24-bitcode.
3. Character quality is poor. It is worst for curve shaped characters.
Q.]Differentiate between Random Scan and Raster Scan
Q.]Compare vector scan display and raster scan display
Oblique projection – the projection direction is not a normal one to the plane;
it gives a better view and it is categorized as
1 Cavalier projection
2 Cabinet projection
Q.]Apply the Liang-Barsky algorithm to the line with co-ordinate (30,60) &
(60,25) against the window:
(Xmin, Ymin) = (10.10) & (Xmax,Ymax) = (50,50)
Given:
(Xmin,Ymin)=(10,10) and (Xmax,Ymax)=(50,50)
P1 (30, 60) and P2 = (60, 25)
Solution:
Set Umin = 0 and Umax = 1
ULeft= q1 / p1
= X1 – Xmin / - Δ X
= 30 – 10 / - (60 - 30)
= 20 / - 30
= -0.67
URight= q2 / p2
= Xmax – X1/ ΔX
= 50 – 30 / (60 - 30)
= 20 / 30
= 0.67
UBottom= q3 / p3
= Y1 – Ymin / - ΔY
= 60 – 10 / - (25 – 60)
= 50 / 35
= 1.43
UTop= q4 / p4
= Ymax – Y1 / ΔY
= 50 – 60 / (25 - 60)
= -10 / - 35
= 0.29
Since ULeft=−0.57which is less than Umin. Therefore we ignore it.
Similarly UBottom=1.43 which is greater than Umax. So we ignore it.
URight=Umin = 0.67 (Entering)
UTop=Umax = 0.29 (Exiting)
We have UTop= 0.29 and URight= 0.67
Q – P = (ΔX, ΔY) = (30, -35)
Since Umin>Umax, there is no line segment to draw