0% found this document useful (0 votes)
20 views27 pages

Unit - 2 Windowing & Clipping

The document discusses the concepts of windowing and clipping in computer graphics, defining key terms such as world coordinates, device coordinates, windows, and viewports. It explains the process of transforming coordinates from a window to a viewport and details various clipping operations, including point, line, polygon, and curve clipping. Additionally, it introduces algorithms like Cohen-Sutherland for line clipping and Sutherland-Hodgeman for polygon clipping, as well as the concept of exterior clipping for applications requiring the preservation of areas outside a specified region.

Uploaded by

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

Unit - 2 Windowing & Clipping

The document discusses the concepts of windowing and clipping in computer graphics, defining key terms such as world coordinates, device coordinates, windows, and viewports. It explains the process of transforming coordinates from a window to a viewport and details various clipping operations, including point, line, polygon, and curve clipping. Additionally, it introduces algorithms like Cohen-Sutherland for line clipping and Sutherland-Hodgeman for polygon clipping, as well as the concept of exterior clipping for applications requiring the preservation of areas outside a specified region.

Uploaded by

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

UNIT – 2

WINDOWING AND CLIPPING


WINDOWING and CLIPPING
Viewing Transformation: A mechanism for displaying a view of a picture on an output device. A
graphics package allows a user to specify which part of the picture is to be displayed and where that part
is to be placed on the display device.

Transformations from world to device coordinates involve translation, rotation and scaling operations
and procedures for deleting those parts of the picture that are outside the limits of a selected display area.

➢A world coordinate area selected for display is called a “window”.

➢An area on a display device to which a window is mapped is called a “viewport”.


➢The window defines what is to be viewed; the viewport defines where it is to be display.
➢The mapping of a part of a world – coordinate scene to device coordinates is referred to as a viewing
transformation or window – to – viewport transformation or windowing transformation.
General Terms:
➢World coordinate – It is the Cartesian coordinate w.r.t which we define the diagram, like Xwmin,
Xwmax, Ywmin, Ywmax
➢Device Coordinate –It is the screen coordinate where the objects are to be displayed, like Xvmin,
Xvmax, Yvmin, Yvmax
• We construct the scene in world coordinates using the output primitives and attributes.
• To obtain a particular orientation for the window, we can set up a two – dimensional viewing
coordinate system in the world – coordinate plane, and define a window in the viewing – coordinate
system.
• All parts of the picture that lie outside the viewport are clipped, and the contents of the viewport are
transferred to device coordinate.
Clipping procedures have fundamental importance in computer graphics. They are used in drawing
packages to eliminate parts of a picture inside or outside of a designated screen area, and in many other
applications.
2 – D Viewing Transformation
➢Convert from Window coordinates to Viewport coordinates.
➢(Xw, Yw) → (Xv, Yv)
➢Maps a world coordinate window to a screen coordinate viewport.
➢Window defined by : (Xw1, Yw1), (Xw2, Yw2)
➢Viewport defined by : (Xv1, Yv1), (Xv2, Yv2)
➢Basic idea is to maintain proportionality.
Window to Viewport coordinate transformation: A window is specified by four world coordinates
Xwmin, Xwmax, Ywmin, Ywmax. Similarly a viewport is described by four normalized device
coordinates Xvmin, Xvmax, Yvmin, Yvmax. The objective of the window to viewport mapping is to
convert the world coordinate (Xw, Yw) of any point to its corresponding normalized device coordinates
(Xv, Yv).
(xw, yw): A point on Window, (xv, yv): Corresponding point on Viewport
We have to calculate the point (xv, yv)
In order to maintain the same relative placement of the point in the viewport as in the window, we
require
Xv – Xvmin = Xw – Xwmin
Xvmax – Xvmin Xwmax – Xwmin

Yv – Yvmin = Yw – Ywmin
Yvmax – Yvmin Ywmax – Ywmin
Solve these expression for the viewport position (Xv, Yv), we can rewrite above equation as:

Xv = (Xvmax – Xvmin) * (Xw – Xwmin) + Xvmin


(Xwmax – Xwmin)

Xv = Xvmin + (Xw – Xwmin) * Sx


Similarly for Y
Yv = (Yvmax – Yvmin) * (Yw – Ywmin) + Yvmin
(Ywmax – Ywmin)
Yv = Yvmin + (Yw – Ywmin) * Sy
Where
Sx = (Xvmax – Xvmin) / (Xwmax – Xwmin)
Sy = (Yvmax – Yvmin) / (Ywmax – Ywmin)
The conversion is performed with the following sequence of transformation:
▪ Perform a scaling transformation using fixed point position of (Xwmin, Ywmin) that scales the
window area to the size of the viewport.
▪ Translate the scaled window area to the position of the viewport.
Relative proportion of objects are maintained if the scaling factor are the same ( Sx = Sy).
Any number of output devices can be open in a particular application, and another window – to –
viewport transformation can be performed for each open output device. This mapping is called the
workstation transformation.
CLIPPING OPERATIONS: Elimination of parts of scene outside a window or viewport is called
clipping.
Any procedure that identifies these portions of a picture that are either inside or outside of a specified
region of space is referred as a clipping algorithm or simply clipping.
Applications of clipping are:
➢Extracting parts of a defined scene for viewing.
➢Locating visible surfaces in 3D views.
➢Anti – aliasing line segments or boundaries of objects.
➢Creating objects using solid modelling procedures.
➢Displaying a multiwindow environment.
➢Drawing and pointing operations which allow parts of a picture to be selected for operations such as
copying, moving, erasing or duplicating.
➢The clip window can be general polygon or any curved boundary.
Different types of clipping are:
1. Point Clipping
2. Line Clipping
3. Polygon Clipping
4. Curve Clipping
5. Text Clipping
1. POINT CLIPPING: Assume that the clip window is a rectangle.
i. Given :
➢A point (x,y)
➢Clipping rectangle (window or viewport)
(Xmin, Ymin, Xmax, Ymax)
ii. Point test:
If the inequality satisfies
Xwmin < = X < = Xwmax
Ywmin < = Y < = Ywmax
Then the point (x,y) lies inside the clip area.
If any of the four inequalities does not hold, the point is outside the clipping rectangle.
2. LINE CLIPPING: A line clipping procedure
➢Test a given line segment whether it lies completely inside the clipping window.
➢If it does not, determine whether it lies completely outside the window.
➢If we cannot identify a line completely inside or completely outside, then perform intersection
calculations with one or more clipping boundaries.
➢We process the line through the “inside – outside” tests by checking the line endpoints.
• As in the above figure, a line with both endpoints inside all clipping boundaries, such as the line from
P1 to P2 is saved.
• A line with both endpoints outside any one of the clip boundaries like line P3, P4 is outside the
window.
• All other lines cross one or more clipping boundaries, and may require calculation of multiple
intersection points.
• Find intersections with the rectangle boundaries.
Cohen-Sutherland Clipping: The Cohen – Sutherland algorithm is a line clipping algorithm. This is the
efficient algorithm which performs initial tests on a line to determine whether intersection calculations
can be avoided. This algorithm divides a 2D space into 9 regions of which only middle part (viewport) is
visible.

➢Every line end point in a picture is assigned a four digit binary code called a region code.
➢Region code identifies the location of the point relative to the boundaries of the clipping rectangle.
Bit Bit Bit Bit
4 3 2 1
Above / Below / Right Left
Top Bottom

Region Code

Binary Regional Codes assigned to the line end points


All lines fall into one of the three categories:
1. Both endpoints lie inside the clip rectangle / window – Accept the entire line.
2. Both endpoints outside clip rectangle on the same side of one of its borders – Reject entire line.
3. Neither 1 nor 2 – chop off part of line outside one of borders and repeat.
Algorithm:
Steps
1) Assign the region codes to both endpoints.
2) Perform OR operation on both of these endpoints.
3) if OR = 0000,
then it is completely visible (inside the window).
else
Perform AND operation on both these endpoints.
i) if AND ? 0000,
then the line is invisible and not inside the window. Also, it can’t be considered for
clipping.
ii) else
AND = 0000, the line is partially inside the window and considered for clipping.
4) After confirming that the line is partially inside the window, then we find the intersection with the
boundary of the window. By using the following formula:-
Slope:- m= (y2-y1)/(x2-x1)
a) If the line passes through top or the line intersects with the top boundary of the window.
x = x + (ywmax – y)/m
y = ywmax
b) If the line passes through the bottom or the line intersects with the bottom boundary of the window.
x = x + (ywmin – y)/m
y = ywmin
c) If the line passes through the left region or the line intersects with the left boundary of the window.
y = y+ (xwmin – x)*m
x = xwmin
d) If the line passes through the right region or the line intersects with the right boundary of the
window.
y = y + (xwmax -x)*m
x = xwmax
5) Now, overwrite the endpoints with a new one and update it.
6) Repeat the 4th step till your line doesn’t get completely clipped

LINE CLIPPING
Midpoint Subdivision Algorithm:

The line is divided at its midpoint into two shorter line segments. Lines which cross one or two
boundaries, we have to clip and fall in category 3. Category 1 lines are completely in the visible region
and lines in category 2 are not visible and lie outside the window. Each segment in category 3 is again
divided into shorter segments and categorized.
The bisection process and categorization is continued until each line segment that encompasses an
intersection point across window boundaries reaches a threshold for line size and all other segments are
either in category 1(visible) or in category 2(invisible). The midpoint coordinates (Xm, Ym) of a line
joining (X1, Y1) and (X2, Y2) are given by Xm = (X1 + X2) / 2 and Ym = (Y1 + Y2) / 2. In the above
figure we can determine the two intersection points M1 and M2 with 7 bisections using the midpoint
subdivision algorithm.
AREA CLIPPING:
To clip polygons, we cannot use the line clipping algorithm, we need to modify the line – clipping
procedures. A polygon processed with a line clipper may be displayed as a series of unconnected line
segments.
For polygon clipping, we require an algorithm that will generate one or more closed areas that can fill
the area. The output of a polygon clipper should be a sequence of vertices that defines the clip polygon
boundaries.
SUTHERLAND – HODGEMAN POLYGON CLIPPING:
Sutherland - Hodgeman clipping is used for polygon clipping. The algorithm operates on the vertices of
the polygon. The simple problem is to clip a polygon against a single clipping edge. We clip the polygon
on all four edges by clipping the entire polygon against one edge, then taking the resulting polygon and
clipping against a second edge and so on for all four edges.
Four possible situations while processing
1. If the first vertex is outside the window boundary and the second vertex is inside, both the intersection
point of the polygon edge with the window boundary and the second vertex are added to the output
vertex list.
2. If both vertexes are inside window boundary. Then only second vertex is added to the output list.
3. If the first vertex is inside the window and second is an outside window. The edge which intersects
with window is added to output list.
4. If both vertices are the outside window, then nothing is added to output list.

Note: Once all the


vertices have been
processed for one clip
window boundary, the
output list of vertices is
clipped against the next
window boundary.
TEXT CLIPPING:

There are several techniques that can be used to provide text clipping in a graphics package. The
different methods are:

a) All – or – none string clipping.


b) All – or – none character clipping.

c) Clip components of individual characters.


CURVE CLIPPING:

Areas with curved boundaries can be clipped. Curve – clipping procedures will involve nonlinear
equations. The bounding rectangle for a circle or other curved object can be used first to test for overlap
with a rectangular clip window. If the bounding rectangle for the object is completely inside the window,
we save the object. If the rectangle is determined to be completely outside the window, we discard the
object.
EXTERIOR CLIPPING:

Till now procedures were used to clip a picture to the interior of a region by eliminating everything
outside the clipping region. That is, we save only the inside 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”.

Exterior clipping is used in other applications that require overlapping pictures.

Example: design of page layouts in advertising or publishing applications or for adding labels or design
patterns to a picture.

You might also like