0% found this document useful (0 votes)
43 views

Q.) Explain Scan Line Algorithm of Polygon Clipping

The scan line algorithm clips polygons by: 1) Finding the intersection points of scan lines with polygon edges and sorting them from left to right. 2) Filling the polygon between pairs of intersections by setting frame buffer positions to a fill color. 3) Iteratively intersecting scan lines with polygon edges from Ymin to Ymax and filling between intersection point pairs.

Uploaded by

Jay Bhakhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Q.) Explain Scan Line Algorithm of Polygon Clipping

The scan line algorithm clips polygons by: 1) Finding the intersection points of scan lines with polygon edges and sorting them from left to right. 2) Filling the polygon between pairs of intersections by setting frame buffer positions to a fill color. 3) Iteratively intersecting scan lines with polygon edges from Ymin to Ymax and filling between intersection point pairs.

Uploaded by

Jay Bhakhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

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

Q.]Compare Bitmap Graphics and Vector based graphics.


Q.]Rephrase the Bresenham’s algorithm to plot 1/8th of the circle and
write the algorithm required to plot the same.
The key feature of circle that it is highly symmetric. So, for whole 360 degree
of circle we will divide it in 8-parts each octant of 45 degree. In order to that we
will use Bresenham’s Circle Algorithm for calculation of the locations of the
pixels in the first octant of 45 degrees. It assumes that the circle is centered on
the origin. So for every pixel (x, y) it calculates, we draw a pixel in each of the
8 octants of the circle as shown below:

Algorithm: Plotting 8 points, each point in


Step 1: Read the radius of circle one octant
(r). Call Putpixel (X + h, Y + k).
Step 2: Set decision parameter d = Call Putpixel (-X + h, Y + k).
3 – 2r. Call Putpixel (X + h, -Y + k).
Step 3: x=0 and y=r. Call Putpixel (-X + h, -Y + k).
Step 4: do Call Putpixel (Y + h, X + k).
{ Call Putpixel (-Y + h, X + k).
Plot (x,y) Call Putpixel (Y + h, -X - k).
If(d<0) then Call Putpixel (-Y + h,-X + k).
{
d = d + 4x + 6
}
Else
{
d=d + 4(x-y) + 10
y=y-1
}
X=x-1
}
While(x<y)
Step 5: stop
Q.]Describe the vector scan display techniques with neat diagram. 4 M
 A pen plotter operates in a similar way and is an example of a randomscan,
hard-copy device.
 When operated as a random-scan display unit, a CRT has the electron beam
directed only to the parts of the screen where a picture is to be drawn.
 Random scan monitors draw a picture one line at a time and for this reason
are also referred to as vector displays (or stroke-writing or calligraphic
displays).
 Here the electron gun of a CRT illuminate’s points and / or straight lines in
any order. If we want a line connecting point A with point B on vector
graphics display, we simply drive the beam reflection circuitry, which will
cause beam to go directly from point A to point B.
 Refresh rate on a random-scan system depends on the number of lines to
be displayed.
 Picture definition stored as a set of line drawing commands in an area of
memory called “refresh display file” or also called as display list or display
program or refresh buffer.
 To display a given picture, the system cycles through the set of commands in
the display file, drawing each component line by line in turn. After all line
drawing commands have been processed, the system cycles back to the first line
drawing command in the list. And repeats the procedure of scan, display and
retrace.
 This displays to draw all the component lines of picture 30 to 60
frames/second
 Random scan system is designed for line drawing applications; hence cannot
display realistic shaded scenes.
 Vector displays produces smooth line drawings but raster produces jagged
lines that are plotted points
 Random scan suitable for applications like engineering and scientific
drawings
 Graphics patterns are displayed by directing the electron beam along the
component lines of the picture
 A scene is then drawn one line at a time by positioning the beam to fill in
the line between specified end points

Q.]Write a program in ‘C’ to generate Hilbert’s curve.


#include <stdio.h> int gm,gd=DETECT;
#include <stdlib.h> initgraph(&gd,&gm,NULL);
#include <graphics.h> moveto(x,y);
#include <math.h> hilbert(r,d,l,u,n,h,x,y);
void move(int j,int h,int &x,int &y) delay(10000);
{ closegraph();
if(j==1) return 0;
y-=h; }
else if(j==2) Q.]Write a Program in ‘C’ for
x+=h; DDA Circle drawing algorithm
else if(j==3) Ans #include<stdio.h>
y+=h; #include<conio.h>
else if(j==4) #include<graphics.h>
x-=h; #include<math.h>
lineto(x,y); void main()
} {
void hilbert(int r,int d,int l,int u,int int
i,int h,int &x,int &y) gdriver=DETECT,gmode,errorcode,
{ tmp,i=1,rds;
if(i>0) float st_x,st_y,x1,x2,y1,y2,ep;
{ initgraph(&gdriver,&gmode,"C:\\
i--; TC\\BGI");
hilbert(d,r,u,l,i,h,x,y); printf("Enter Radius:");
move(r,h,x,y); scanf("%d",&rds);
hilbert(r,d,l,u,i,h,x,y); while(rds>pow(2,i))
move(d,h,x,y); i++;
hilbert(r,d,l,u,i,h,x,y); ep=1/pow(2,i);
move(l,h,x,y); x1=rds; y1=0;
hilbert(u,l,d,r,i,h,x,y); st_x=rds; st_y=0;
} do
} { x2=x1+(y1*ep);
int main() y2=y1-(x2*ep);
{ putpixel(x2+200,y2+200,10);
int n,x1,y1; x1=x2;
int y1=y2;
x0=50,y0=150,x,y,h=10,r=2,d=3,l=4 }while((y1-st_y)<ep || (st_x-
,u=1; x1)>ep);
printf)"\nGive the value of n: "); getch();
scanf(“%d”,&n); }
x=x0;y=y0;

Q.]Explain types of Parallel Projection with example. 4M


 Orthographic projection – the projection direction is a normal one to theplane
and it is categorized as
1 Top projection
2 Front projection
3 Side projection

 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.]Explain curve generation using Interpolation technique. 4 M


Specify a spline curve by giving a set of coordinate positions, called control
points, which indicates the general shape of the curve These, control points are
then fitted with piecewise continuous parametric polynomial functions in one of
two ways. When polynomial sections are fitted so that the curve passes through
each control point, the resulting curve is said to interpolate the set of control
points. On the other hand, when the polynomials are fitted to the general
control-point path without necessarily passing through any control point, the
resulting curve is said to approximate the set of control points interpolation
curves are commonly used to digitize drawings or to specify animation paths.
Approximation curves are primarily used as design tools to structure object
surfaces an approximation spline surface credited for a design application.
Straight lines connect the control-point positions above the surface.

Q.] Explain boundary fill algorithm with pseudo code


Limitations:
 There is a problem with this technique. Consider the case following, where
we tried to fill the entire region. Here, the image is filled only partially. In such
cases, 4-connected pixels technique
cannot be used.

Q.]Explain inside and outside test for polygon. 4 M


This method is also known as counting number method. While filling an
object, we often need to identify whether particular point is inside the object
or outside it.There are two methods by which we can identify whether particular
point is inside an object or outside namely, Odd-Even Rule, and Non-zero
winding number rule.
1. Odd-Even Rule:
In this technique, we count the edge crossing along the line from any point
(x, y) to infinity. If the number of interactions is odd then the point (x, y) is
an interior point. If the number of interactions is even then point (x, y) is an
exterior point.Here is the example to give you the clear idea,
From the Fig., we can see that from the point (x, y), the number of interactions
point on the left side is 5 and on the right side is 3. So the total number of
interaction point is 8, which is odd. Hence, the point is considered within the
object.

2. Non-zero Winding Number Rule:


This method is also used with the simple polygons to test the given point is
interior or not. It can be simply understood with the help of a pin and a
rubber band.Fix up the pin on one of the edge of the polygon and tie-up the
rubber band in it and then stretch the rubber band along the edges of the
polygon.When all the edges of the polygon are covered by the rubber band,
check out the pin which has been fixed up at the point to be test. If we find at
least one wind at the point consider it within the polygon, else we can say that
the point is not inside the polygon.
In another alternative method, give directions to all the edges of the polygon.
Draw a scan line from the point to be test towards the left most of X direction.
Given the value 1 to all the edges which are going to upward direction and
all other – 1 as direction values.Check the edge direction values from which the
scan line is passing and sum up them.
If the total sum of this direction value is non-zero, then this point to be tested
is an interior point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the scan line
is passing then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is
said to be an interior point.

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

You might also like