Upload
surendra-singh-chauhan
View
216
Download
0
Embed Size (px)
Citation preview
8/8/2019 Graphics 8
1/10
Homework Title / No. : 4 Course Code: CAP405
Course Instructor: MR. SANJAY SOOD
DOA: APR 24, 2010 DOS: MAY 10,2010
Students Roll No:-RD3803B37 Section No. : D3803
Declaration:I declare that this assignment is my individual work. I have not
copied from any other students work or from any other source
except where due acknowledgment is made explicitly in thetext, nor has any part been written for me by another person.
Students Signature:
NITI MALHOTRA
Evaluators comments:
________________________________________________________________
_____
Marks obtained: ___________ out of ______________________
Part A
1)While clipping a polygon, it is said that Sutherland
Hodgeman is a better method than Weiler Atherton
polygon clipping algorithm. Perform clipping on a
Polygon and justify the above statement.
Answer:-
The SutherlandHodgman algorithm is used for clipping
polygon. It works by extending each line of the convex clip
polygon in turn and selecting only vertices from the subject
polygon those are on the visible side.
8/8/2019 Graphics 8
2/10
The algorithm begins with an input list of all vertices in thesubject polygon. Next, one side of the clip polygon is extendedinfinitely in both directions, and the path of the subject polygonis traversed. Vertices from the input list are inserted into an
output list if they lie on the visible side of the extended clippolygon line, and new vertices are added to the output listwhere the subject polygon path crosses the extended clippolygon line.
This process is repeated iteratively for each clip polygon side,using the output list from one stage as the input list for thenext. Once all sides of the clip polygon have been processed,the final generated list of vertices defines a new single polygonthat is entirely visible. Note that if the subject polygon wasconcave at vertices outside the clipping polygon, the newpolygon may have coincident (i.e. overlapping) edges this isacceptable for rendering, but not for other applications such ascomputing shadows.
All steps of clipping concave polygon 'W' by 5-sided convexpolygon
The Weiler Atherton algorithm overcomes this by returninga set of divided polygons, but is more complex andcomputationally more expensive, and algorithm requirespolygons to be clockwise and not reentrant (self intersecting).
The algorithm can support holes (as counter-clockwise polygons
8/8/2019 Graphics 8
3/10
wholly inside their parent polygon), but requires additionalalgorithms to decide which polygons are holes.
So SutherlandHodgman is used for many rendering
applications and is better than weiler Atherton algorithmSutherlandHodgman can also be extended into 3D space byclipping the polygon paths based on the boundaries of planesdefined by the viewing space.
2) Write a procedure for area-Subdivision algorithm
for visible surface.
Answer:-
1. We first classify each of the surfaces, according to theirrelations with the area:
Surrounding surface - a single surface completely enclosesthe area.
Overlapping surface - a single surface that is partly inside
and partly outside the area.
Inside surface - a single surface that is completely inside thearea.
Outside surface - a single surface that is completely outsidethe area.
To improve the speed of classification, we can make use of the
bounding rectangles of surfaces for early confirmation orrejection that the surfaces should be belong to that type.
8/8/2019 Graphics 8
4/10
2. Check the result from 1., that, if any of the followingcondition is true, then, no subdivision of this area is needed.
a. All surfaces are outside the area.b. Only one surface is inside, overlapping or surrounding surfaceis in the area.c. A surrounding surface obscures all other surfaces within thearea boundaries.For cases b and c, the color of the area can be determined from
that single surface.
3)Write a program that allows a user to design a
picture from a menu of basic shapes by dragging
each selected shape into position with a pick device.
Answer:-
#include #include #include
#include#includeunion REGS in, out;int cirrad1=0,cirrad2;void detectmouse (){
in.x.ax = 0;int86 (0X33,&in,&out);if (out.x.ax == 0)
printf ("\nMouse Fail To Initialize");else
printf ("\nMouse Succesfully Initialize");}void showmousetext (){
in.x.ax = 1;int86 (0X33,&in,&out);
}
void showmousegraphics (){
8/8/2019 Graphics 8
5/10
in.x.ax = 1;int86 (0X33,&in,&out);getch ();
closegraph ();}void hidemouse (){
in.x.ax = 2;int86 (0X33,&in,&out);
}void draw (){ while(out.x.bx!=2)
{int x,y,x1,y1;in.x.ax = 3;int86 (0X33,&in,&out);cleardevice();
if (out.x.bx == 1){
x = out.x.cx;y = out.x.dx;setcolor(10);circle(x,y,cirrad1);
}if (out.x.bx == 1){
x = out.x.cx;y = out.x.dx;setcolor(10);circle(x,y,cirrad2);
}if (out.x.bx == 1){
x = out.x.cx;y = out.x.dx;//setcolor(10);
// circle(x,y,cirrad2);}if (out.x.bx == 1)
{
8/8/2019 Graphics 8
6/10
x1 = out.x.cx;y1 = out.x.dx;
}line(x,y,x+34,y+23);
line(x,y,x-90,y-0);delay (10);}
getch();
}int main (){
cout>cirrad2;clrscr();int gdriver = DETECT, gmode, errorcode;initgraph(&gdriver, &gmode, "d:\\tc\\bgi");detectmouse ();showmousetext ();draw ();hidemouse ();getch ();return 0;
}
Part B
4)Design the scan-line algorithm for the removal ofhidden lines from a scene.
Answer:-
The algorithm is as follows:-
1. Initialization:-
Initial each screen pixel to a background color.
Set y to the smallest ymin value in the edge list.
8/8/2019 Graphics 8
7/10
Repeat steps 2 and 3 until no further processing can be
performed.
2. Y-scan loop:-
Activate edge whose ymin=y. sort active edge in order of
increasing x.
3. X-scan loop:-
Process, from left to right, each active edge as follows:-
Invert the IN/OUT flag of the polygon in the polygon list
which contains the edge. Count the number of active
polygons whose IN/OUT flag is set to IN. if the number is 1,only one polygon is visible. All pixel values from this edge
and up to next edge are set to the colour of the polygon. If
this number is greater than 1, determine the visible
polygon by the smallest z value of each polygon at the
pixel under consideration. These z values are found from
the equation of the plane containing the polygon. The pixel
from this edge and up to the next edge are set to the
colour of this polygon, unless the polygon becomesobscured by another before the next edge is reached, in
which case we set the remaining pixel to the colour of the
obscuring polygon. If this number is 0, pixel from this edge
and up to the next one is left unchanged.
When the last active edge is processed, we proceed as
follows:-
Remove those edges for which the values of ymax
equal the present scan line value y. if no edge
remain, the algorithm has finished.
For each remaining active edge, in order, replace x by
x+1/m. this is the edge intersection with the next
scan line y+1.
Increment y to y+1, the next scan line, and repeat
step 2.
8/8/2019 Graphics 8
8/10
5)Suppose you are given an image. How will you
detect the presence of Hidden surfaces and remove
hindrance from the image?
Answer:-
The need of removing what is not visible has been and always
will be extremely high in the gaming industry, even though
graphic cards evolve at gigantic rates and things that were true
a couple years ago are not even remotely true these days.
When a game is created a goal frame rate[*] is set.
Hidden Surface Removal follows two approaches:-
Object-space techniquesApplied before vertices are mapped to pixels
Image-space techniquesApplied after vertices have been rasterized
Hidden surface removal algorithms: -
Z-buffering: -
Z-buffering is the mana of image depth coordinates in three-dimensional (3-D) graphics, usually done in hardware,sometimes in software. It is one solution to the visibilityproblem, which is the problem of deciding which elements of arendered scene are visible, and which are hidden. The painter'salgorithm is another common solution which, though lessefficient, can also handle non-opaque scene elements. Z-
buffering is also known as depth buffering.
Ray tracing: -
Ray tracing is a technique for generating an image by tracingthe path of light through pixels in an image plane andsimulating the effects of its encounters with virtual objects. Thetechnique is capable of producing a very high degree of visualrealism, usually higher than that of typical scanline rendering
http://www.devmaster.net/articles/hidden-surface-removal/#Glossaryhttp://www.devmaster.net/articles/hidden-surface-removal/#Glossary8/8/2019 Graphics 8
9/10
methods, but at a greater computational cost. This makes raytracing best suited for applications where the image can berendered slowly ahead of time, such as in still images and filmand television special effects, and more poorly suited for real-
time applications like computer games where speed is critical.Ray tracing is capable of simulating a wide variety of opticaleffects, such as reflection and refraction, scattering, andchromatic aberration.
Binary space partitioning:-
Binary space partitioning (BSP) is a method for recursively
subdividing a space into convex sets by hyper planes. Thissubdivision gives rise to a representation of the scene by meansof a tree data structure known as a BSP tree.
Originally, this approach was proposed in 3D computer graphicsto increase the rendering efficiency. Some other applicationsinclude performing geometrical operations with shapes in CAD,collision detection in robotics and 3D computer games, andother computer applications that involve handling of complex
spatial scenes.
Painter's algorithm: -
The painter's algorithm, also known as a priority fill, is oneof the simplest solutions to the visibility problem in 3Dcomputer graphics. When projecting a 3D scene onto a 2Dplane, it is necessary at some point to decide which polygonsare visible, and which are hidden.
The name "painter's algorithm" refers to the techniqueemployed by many painters of painting distant parts of a scenebefore parts which are nearer thereby covering some areas of
distant parts. The painter's algorithm sorts all the polygons in ascene by their depth and then paints them in this order, farthest
8/8/2019 Graphics 8
10/10
to closest. It will paint over the parts that are normally notvisible thus solving the visibility problem at the cost ofhaving painted redundant areas of distant objects.
6)Is Z-buffer better than other hidden surfacealgorithm? Give reasons.
Answer:-
Yes, z-buffer is better than hidden surface algorithm because
It is a commonly used image-space approach to hidden-surface removal.
It is also referred as Depth-Buffer method.
Use the intensity color of the nearest 3D point for eachpixel.
It contains 2 buffers:- Frame buffer stores image information. Z-buffer depth information with the same
resolution.No, other algorithm provides such type of buffers. So its betterthan other algorithms.