Sie sind auf Seite 1von 15

HOME-WORK # 3

COMPUTER GRAPHICS

SUBMITTED TO:

MR DHIRAJ SONI

SUBMITTED BY:

RAJESH RANA

ROLL NO. 16

REG. NO. 7010070005

BCA (H) – MCA

LOVELY PROFESSIONAL UNIVERSITY


Part A:
1).Derive a matrix for Window to viewport
transformation and also discuss the importance of
window to viewport transformation

Ans. Importance of Window to viewport transformation:-

 Panning

 Moving the window around the world

 Zooming

 Reducing/increasing the window size

In general the objects and primitives represented in the


application model will be stored in world coordinates, that is
their size, shape, position, etc. will be given in terms of logical
units for whatever the object represent (e.g. mm, cm, m, km or
light years). Thus to display the appropriate images on the screen
(or other device) it is necessary to map from world coordinates to
screen or device coordinates. This transformation is known as the
window to viewport transformation, the mapping from the world
coordinate window2 to the viewport (which is given in screen
coordinates).

In general the window to viewport transformation will involve a


scaling and translation as where the scaling in non-uniform (the
vertical axis has been stretched). Non uniform sculling result from
the world coordinate window and viewport having different
aspect ratios.The screen window (that is the viewport) covers only
part of the screen.The transformation is generally achieved by a
translation in world coordinates, a scaling to viewport
coordinates and another translation in viewport coordinates,
which are generally composed to give a single transformation
matrix.

The window-to-view port transform is:

1. Translate the window’s lower-left corner to the origin.

2. Scale width and height of window to match view port’s.

3. Translate corner at origin to lower-left corner in view port.

t x   xmin t y   ymin

umax  u min vmax  vmin


sx  sy 
xmax  xmin ymax  ymin

t x  u min t y  vmin

►The final window-to-view port transform is:

 u  umin vmax -vmin 


M WV  T  u min ,vmin  S  max , T  -xmin ,-ymin 
 xmax  xmin ymax -ymin 
 u max  u min 
x  x 0 0
1 0 umin   max min
 1 0  xmin 
  vmax  vmin
 0 1 vmin   0 0 0 1  ymin 
 ymax  ymin 
0 0 1    1 
0 0 1  0 0
 
 
 u max  u min u  u min 
x  x 0  xmin max  u min 
xmax  xmin
 max min

vmax  vmin v v
 0  ymin max min  vmin 
  ymax  ymin ymax  ymin 
 0 0 1 
 
 
 Multiplying the matrix Mwv by the point p gives: -

 u max  u min 
  x  x min   u min 
 x max  x min 
 
 v max  v min 
p '   y  y min   v min 
 y max  y min 
 
 
 1 
 

2).WAP to Implement the cohen- sutherland line


clipping algorithm.

Ans.

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

Void main()
{

float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;
int gd,gm;

detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");

cout<<"\n\n\tEnter the co-ordinates of Line :";


cout<<" \n\n\tX1 Y1 : ";
cin>>%f %f",&x1,&y1;
cout<<"\n\n\tX2 Y2 : ");
cin>>%f %f",&x2,&y2);

cout<<"\n\tEnter the co_ordinates of window :\n ");


cout<<"\n\txwmin , ywmin : ");
cin>>%f %f",&xwmin,&ywmin);
cout<<"\n\txwmax , ywmax : ");
cin>>%f %f",&xwmax,&ywmax);

line(x1,y1,x2,y2);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();
cleardevice();

lineclip(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax );
getch();
closegraph();

3).Can we say that like images, texts can also be


clipped? If yes, justify your answer by taking an
example text and perform clipping.

Ans. we can split clipping into area clipping or line clipping. Area


clipping is used in the case where characters are represented by a
bitmap, and line clipping is practical if characters are represented
by lines. But, in the majority of cases we use characters composed
from lines and curves, so-called vectors. Its advantage is that we
can zoom or scale, without a loss of quality.
According to how precise we want the clipping of a text, we
categorize clipping a text as follows: 
 precise clipping
 clipping to a character
 clipping a text by words or whole row.

In normal text coding, each character is represented by one value


totaling 1 byte. In clipping, we should look at a character as an
inseparable object. Every character comprises a minimum
rectangle, which we will call a 'character envelope'. While
clipping a character to a character, we test whether the center of
an envelope is in the display box, or whether the envelope is
wholly inside the display box or not. On the basis of this we
decide whether to display the given character

Yes text can also be clipped like pictures.

Text Clipping:-

Example:-
Before Clipping After Clipping

Part B:

1) Elaborate how Sutherland hodgeman is better then


weiler Atherton polygon clipping algorithm.

Ans Polygon clipping is one of those humble tasks


computers do all the time.

How Sutherland hodgeman is better :

Sutherland-Hodgman uses a divide-and-conquer strategy to attack


the problem. First, it clips the polygon against the right clipping
boundary. The resulting, partly clipped polygon is then clipped
against the top boundary, and then the process is repeated for the
two remaining boundaries. It's a basic operation in creating
graphic output of all kinds.The oldest one (from 1974) is calledthe
Sutherland-Hodgman algorithm.It is relatively simple. It is also
very efficient in two important cases, one being when the polygon
is completely inside the boundaries, and the other when it's
completely outside.
The weiler Atherton polygon clipping algorithm is a good deal
more complicated, but in certain cases fewer intersections need to
be calculated than forSutherland-Hodgman. Therefore, it may be
somewhat faster when many polygon lines intersect with the
clipping boundaries. However, it is moresensitive to 'nasty'
polygonsThe Weiler algorithm is even more complicated, but it is
the one you'll need if you want to clip a polygon against a non-
rectangular window.

Even more ways to clip a polygon exist. None of them is totally


perfect. Often, it is possible to feed a weird polygon to an
algorithm and retrieve an incorrect result. One of the vertices will
disappear, or a ghost vertex will be created. Therefore, the hunt
for the perfect clipping algorithm is still open.A polygon is
generally stored as a collection of vertices. Any clipping algorithm
takes one collection, and outputs a new collection. A clipped
polygon, after all, is also a polygon. Notice that the clipped polygon
often will have more vertices than the unclipped one, but it can
also have the same number, or less. If the unclipped polygon lies
completely outside the clipping boundary, the clipped polygon
even has zero vertices.

How it Sutherland works with example


To clip against one boundary, the algorithm loops through all
polygon vertices. At each step, it considers two of them, called
'previous' and 'current.' First, it determines whether these vertices
are inside or outside the clipping boundary. This, of course, is
simply a matter of comparing the horizontal or vertical position
to the boundary's position.

Then, it applies the following simple rules:

If 'previous' and 'current' are both inside: Output 'current.'

If 'previous' is inside, and 'current' is outside: Output the


intersection point of the corresponding edge and the
clipping boundary.

If 'previous' and 'current' are both outside: Do nothing.

If 'previous' is outside, and 'current' is inside: Output the


intersection point, and then o
Weiler-Atherton Polygon Clipper :
 Assume the vertices of the subject polygon are listed in
clockwise order (interior is on the right)
 Start at an entering intersection

 Follow the edge(s) of the polygon being clipped until an


exiting intersection is encountered

 Turn right at the exiting intersection and following clip


window edge until intersection is found

 Turn right and follow the subject polygon

 Continue until vertex already visited is reached

 If entire polygon has not be processed, repeat

 Consider the subject polygon with vertices and the

clip polygon with vertices

 Insert the intersections in both vertex lists

o Subject list:

o Clip list:
 Starting at vertex a of the clip polygon, find 1 is first
entering intersection
 Traversing the subject, find 2 is exiting intersection

 ``Jump'' to vertex 2 in clip polygon, follow until vertex 1


(which has be visited)

 Output clipped list

 Jump back to subject list, restarting at c, find 3 is entering


intersection

 Traversing the subject, find 4 is exiting intersection

 Jump to vertex 4 in clip polygon, follow until vertex 5


(which is entering)

 Jump to subject, at vertex 5, find 6 is exiting

 Jump to clip, at vertex 6, find 3 is visited


 Output clipped list

 All entering intersections have been visited

2) Elaborate the various text clipping techniques used


to clip a text by taking suitable example.

Ans. Various text clipping techniques are:-

1. All or none String clipping:- The simplest method for


processing character strings relative to a window boundary is to
use the all-or-none string-clipping strategy. If all of the string is
inside a clip window, we keep it. Otherwise, the string is
discarded. This procedure is implemented by considering a
bounding rectangle around the text pattern. The boundary
positions of the rectangle are then compared to the window
boundaries, and the string is rejected if there is any overlap. This
method produces the fastest text clipping.

Example:-

Before Clipping After Clipping

2. All or none character clipping:- An alternative to


rejecting an entire character string that overlaps a window
boundary is to use the all-or-none character-clipping strategy.
Here we discard only those characters that are not completely
inside the window. In this case, the boundary limits of individual
characters are compared to the window. Any character that either
overlaps or is outside a window boundary is clipped.

Example:-

3. Clipping individual character:- A final method for


handling text clipping is to clip the components of individual
characters. We now treat characters in much the same way that we
treated lines. If an individual character overlaps a clip window
boundary, we clip off the parts of the character that are outside
the window.

Example:-
3) Differentiate between Interior clipping and Exterior
clipping. In what form exterior clipping can be
useful? Illustrate using some examples? Draw
diagrams to define pictorially?

Ans Difference between Interior and Exterior clipping:- Clipping


a picture to the interior of a region by eliminating everything
outside the clipping region. What is saved by these procedures is
inside the region. In some cases, we want to do the reverse, that is,
we want to clip a picture to the exterior of a specified region. The
picture parts to be saved are those that are outside the region. This
is referred to as exterior clipping.

Example:- Example of the application of exterior clipping is in


multiple window systems. To correctly display the screen windows,
we often need to apply both internal and external clipping. Objects
within a window are clipped to the interior of that window.
When other higher-priority windows overlap these objects, the
objects are also clipped to the exterior of the overlapping windows.

Exterior clipping can be useful:- Exterior clipping is used


also in other applications that require overlapping pictures.
Examples here include the design of page layouts in advertising or
publishing applications or for adding labels or design patterns to
a picture. The technique can also be used for combining graphs,
maps, or schematics. For these applications, we can use exterior
clipping to provide a space for an insert into a larger picture.

Interior clipping
What is to be saved is inside the clip window

Exterior clipping

What is to be saved is outside clip window

Interior clipping

- keep point P2

Exterior clipping

- keep point

Das könnte Ihnen auch gefallen