You are on page 1of 10

Homework Title / No.

: 4 Course Code: CAP


405

Course Instructor: MR. SANJAY SOOD

DOA: APR 24, 2010 DOS: MAY 10,


2010

Student’s Roll No:-RD3803B37 Section No. : D3803

Declaration:
I declare that this assignment is my individual work. I have not
copied from any other student’s work or from any other source
except where due acknowledgment is made explicitly in the
text, nor has any part been written for me by another person.

Student’s Signature:

NITI MALHOTRA

Evaluator’s 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 Sutherland–Hodgman 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.
The algorithm begins with an input list of all vertices in the
subject polygon. Next, one side of the clip polygon is extended
infinitely in both directions, and the path of the subject polygon
is traversed. Vertices from the input list are inserted into an
output list if they lie on the visible side of the extended clip
polygon line, and new vertices are added to the output list
where the subject polygon path crosses the extended clip
polygon line.

This process is repeated iteratively for each clip polygon side,


using the output list from one stage as the input list for the
next. Once all sides of the clip polygon have been processed,
the final generated list of vertices defines a new single polygon
that is entirely visible. Note that if the subject polygon was
concave at vertices outside the clipping polygon, the new
polygon may have coincident (i.e. overlapping) edges – this is
acceptable for rendering, but not for other applications such as
computing shadows.

All steps of clipping concave polygon 'W' by 5-sided convex


polygon

The Weiler Atherton algorithm overcomes this by returning


a set of divided polygons, but is more complex and
computationally more expensive, and algorithm requires
polygons to be clockwise and not reentrant (self intersecting).
The algorithm can support holes (as counter-clockwise polygons
wholly inside their parent polygon), but requires additional
algorithms to decide which polygons are holes.

So Sutherland–Hodgman is used for many rendering


applications and is better than weiler Atherton algorithm
Sutherland–Hodgman can also be extended into 3D space by
clipping the polygon paths based on the boundaries of planes
defined 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 their


relations with the area:

Surrounding surface - a single surface completely encloses


the area.

Overlapping surface - a single surface that is partly inside


and partly outside the area.

Inside surface - a single surface that is completely inside the


area.

Outside surface - a single surface that is completely outside


the area.

To improve the speed of classification, we can make use of the


bounding rectangles of surfaces for early confirmation or
rejection that the surfaces should be belong to that type.
2. Check the result from 1., that, if any of the following
condition 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 surface
is in the area.
c. A surrounding surface obscures all other surfaces within the
area 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 <dos.h>
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
union 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 ()
{
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)
{
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<<"There will be 2 circle followes by a rectangle and
then a line";
cout<<"\nEnter the radius of the two circle ";
cin>>cirrad1;
cin>>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 of


hidden 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.


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 becomes
obscured 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.
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 techniques
Applied before vertices are mapped to pixels
 Image-space techniques
Applied 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 visibility
problem, which is the problem of deciding which elements of a
rendered scene are visible, and which are hidden. The painter's
algorithm is another common solution which, though less
efficient, 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 tracing


the path of light through pixels in an image plane and
simulating the effects of its encounters with virtual objects. The
technique is capable of producing a very high degree of visual
realism, usually higher than that of typical scanline rendering
methods, but at a greater computational cost. This makes ray
tracing best suited for applications where the image can be
rendered slowly ahead of time, such as in still images and film
and 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 optical
effects, such as reflection and refraction, scattering, and
chromatic aberration.

Binary space partitioning:-

Binary space partitioning (BSP) is a method for recursively


subdividing a space into convex sets by hyper planes. This
subdivision gives rise to a representation of the scene by means
of a tree data structure known as a BSP tree.

Originally, this approach was proposed in 3D computer graphics


to increase the rendering efficiency. Some other applications
include performing geometrical operations with shapes in CAD,
collision detection in robotics and 3D computer games, and
other computer applications that involve handling of complex
spatial scenes.

Painter's algorithm: -

The painter's algorithm, also known as a priority fill, is one


of the simplest solutions to the visibility problem in 3D
computer graphics. When projecting a 3D scene onto a 2D
plane, it is necessary at some point to decide which polygons
are visible, and which are hidden.

The name "painter's algorithm" refers to the technique


employed by many painters of painting distant parts of a scene
before parts which are nearer thereby covering some areas of
distant parts. The painter's algorithm sorts all the polygons in a
scene by their depth and then paints them in this order, farthest
to closest. It will paint over the parts that are normally not
visible — thus solving the visibility problem — at the cost of
having painted redundant areas of distant objects.

6) Is Z-buffer better than other hidden surface


algorithm? 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 each
pixel.
• 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 it’s better
than other algorithms.