Clipping
Clipping
Unit 3: Clipping
By
Gaurav Bhattarai
GauravBhattarai
Two Dimensional Viewing (2D-Viewing)
• It is a formal mechanism for displaying views of a picture on an output device.
• A graphics package allows the user to specify:
➢ Which part of the defined picture is to be displayed(Window).
➢ Where the part is to be placed on the display device(Viewport).
➢ A view is selected by specifying a sub area of the total picture area.
• Much like what we see in real life through a small window or the view finder of a
camera.
• In computer graphics several coordinate systems (reference frame) are used to
construct, select views, and display a 2D scene or image.
• Modeling coordinate system
• It is used to define coordinates that are used to construct the shape of
individual parts (objects) of a 2D scene.
• World Coordinate system
• Used to organize the individual objects (points, lines, circles, etc.) into a
scene.
• A scene is made up of a collection of objects.
• These objects make up the "scene" or "world" that we want to view, and
the coordinates that we use to define the scene are called world
coordinates.
GauravBhattarai
• Viewing coordinate system
• Used to define particular view of a 2D scene. Translation, scaling, and
rotation of the window will generate a different view of the scene.
• For a 2-D picture, a view is selected by specifying a subarea of the total
picture area.
Window
• A world-coordinate area selected for display is called a window. That is, window is
the section of the 2D scene that is selected for viewing.
• The window defines what is to be viewed.
• A window can be specified by four world coordinates: xwmin, xwmax, ywmin and
GauravBhattarai
ywmax.
Viewport
• An area on a display device to which a window is mapped is called a viewport.
• The viewport indicates where on an output device selected part will be displayed.
• A viewport can be described by four device coordinates: xvmin, xvmax, yvmin and
yvmax.
Figure given below illustrates the mapping of a 2D picture that falls within a
rectangular window onto a designated rectangular viewpoint.
GauravBhattarai
• Window and viewport are often rectangular in standard positions, because it
simplifies the transformation process and clipping process.
• Other shapes such as polygons, circles take longer time to process.
Applications:
• By changing the position of the viewport, we can view objects at different positions
on the display area of an output device.
• Also by varying the size of viewports, we can change size of displayed objects.
• Zooming effects can be obtained by successively mapping different-sized windows
on a fixed-sized viewport.
• Panning effects are produced by moving a fixed-size window across the various
objects in a scene.
GauravBhattarai
Windows to Viewport Transformation
• It is the mechanism for displaying view of a picture on an output device.
• The world coordinate selected for display is called window.
• The area on the display device to which window is mapped is called viewport.
• So, window defines what is to be viewed and viewport defines where it is to be
displayed.
• The mapping of part of world co-ordinate scene to device co-ordinate is called
viewing transformation or window-to-viewport transformation.
GauravBhattarai
GauravBhattarai
GauravBhattarai
Q) Window port is given by (100, 100, 300, 300) and viewport is given by (50, 50, 150,
150). Convert the window port coordinate (200, 200) to the view port coordinate.
GauravBhattarai
Q) Find the normalization transformation matrix for window to viewport which uses
the rectangle whose lower left corner is at (2, 2) and upper right corner is at (6, 10)
as a window and the viewport that has lower left corner at (0, 0) and upper right
corner at (1,1).
GauravBhattarai
Q) A world coordinate & viewport have the following geometry:
Window (left, right, bottom, top) = (200, 600, 100, 400)
Viewport (left, bottom, width, height) = (0, 0, 800, 600)
The following vertices are drawn in the world:- P1: (356, 125), P2: (200, 354), P3:
(230,400), P4: (564, 200). What coordinate will each occupy in viewport?
GauravBhattarai
GauravBhattarai
Clipping
• The process of discarding (cutting off) those parts of a picture which are outside of
a specified region is called clipping.
• Any procedure that identifies those parts of a picture that are either inside or
outside of the specified region is called a clipping algorithm.
• The region against which the clipping operation is performed is called a clip
window.
GauravBhattarai
Why Clipping?
• Excludes unwanted graphics from the screen.
• Improves efficiency, as the computation dedicated to objects that appear off
screen can be significantly reduced.
• Extracting part of a defined scene for viewing.
• Identifying visible surfaces in three-dimensional views.
• Antialiasing line segments or object boundaries.
• Creating objects using solid-modeling procedures.
• Displaying a multi-window environment.
• Drawing and painting operations that allow parts of a picture to be selected for
copying, moving, erasing, or duplicating.
Applications
• Video editing
• Image Editing
• Defining Animation paths
GauravBhattarai
Point Clipping
• Assuming that the clip window is a rectangle in standard position, we save a point
P=(x, y) for display if the following inequalities are satisfied:
𝑥𝑤𝑚𝑖𝑛 ≤ 𝑥 ≤ 𝑥𝑤𝑚𝑎𝑥
𝑦𝑤𝑚𝑖𝑛 ≤ 𝑦 ≤ 𝑦𝑤𝑚𝑎𝑥
• Where the edges of the clip window (𝑥𝑤𝑚𝑖𝑛 , 𝑥𝑤𝑚𝑎𝑥 , 𝑦𝑤𝑚𝑖𝑛 , 𝑦𝑤𝑚𝑎𝑥 ) can be either
the world coordinate window boundaries or viewport boundaries. If any one of
these four inequalities is not satisfied, the point is clipped.
Algorithm:
1. Get the minimum and maximum coordinates of the viewing plane.
2. Get the coordinates for a point.
3. Check whether given input lies between minimum and maximum coordinates of
viewing plane.
4. If yes, display the point which lies inside the region,
otherwise discard it.
GauravBhattarai
Line Clipping
In line clipping, a line or part of line is clipped if it is outside the window port. There
are three possibilities for the line:
• Line can be completely inside the window (This line should be accepted).
• Line can be completely outside of the window (This line will be completely
removed from the region).
• Line can be partially inside the window (We will find intersection point and draw
only that portion of line that is inside region).
GauravBhattarai
Cohen-Sutherland Line Clipping Algorithm
1. Assign the four digit binary value called region code to each end point of a line.
• Windows edges are processed in TBRL. Here, the region code for point 𝑃1 is
0100 & 𝑃2 is 1001.
• To decide which boundary edges the line crosses, check for the bit position in
line endpoint.
• Line crosses these window boundary edges for which bit position value are
opposite.
Here,
GauravBhattarai
Since, the value at T, B & L are opposite, the line P1-P2 crosses the clipping
window at top, bottom & left edge.
• Now find the point of intersection with the clipping window edge.
• For calculation of intersection point, first find the slope,
GauravBhattarai
Q) Consider a rectangle clipping window with A(20, 20), B(90, 20), C(90, 70) & D(20,
70). Clip the line P1P2 with P1(10, 30) & P2(80, 90) using Cohen-Sutherland line
clipping algorithm.
GauravBhattarai
GauravBhattarai
GauravBhattarai
Q) Use the Cohen-Sutherland algorithm to clip the line P1(70, 20) and P2(100, 10)
against a window lower left hand corner (50, 10) and upper right hand corner (80,
40).
GauravBhattarai
GauravBhattarai
Liang-Barsky Line Clipping Algorithm
This algorithm is considered to be the faster parametric line-clipping algorithm. The
following concepts are used in this clipping:
1. The parametric equation of the line.
2. The inequalities describing the range of the clipping window which is used to
determine the intersection between the line and the clip window.
The parametric equation of a line can be given by,
-u ∆x ≤ x1- xwmin
u ∆x ≤ xwmax - x1
-u ∆y ≤ y1- ywmin
u ∆y ≤ ywmax – y1
GauravBhattarai
u= q1/p1
u= q2/p2
u= q3/p3
u= q4/p4
GauravBhattarai
Else
Calculate the endpoints of the clipped line as follows:
xx1= x1 + u1 ∆ x
xx2= x1 + u2 ∆ x
yy1= y1 + u1 ∆ y
yy2= y1 + u2 ∆ y
GauravBhattarai
GauravBhattarai
Q) Apply Liang Barsky Line Clipping algorithm to the line with coordinates (30, 60)
and (60, 25) against the window (𝒙𝒘𝒎𝒊𝒏 , 𝒚𝒘𝒎𝒊𝒏 ) = (𝟏𝟎, 𝟏𝟎) and (𝒙𝒘𝒎𝒂𝒙, 𝒚𝒘𝒎𝒂𝒙 ) =
(𝟓𝟎, 𝟓𝟎).
GauravBhattarai
GauravBhattarai
Note
Here,
t1= u1
t2= u2
GauravBhattarai
GauravBhattarai
Polygon Clipping
GauravBhattarai
GauravBhattarai
Q) Clip polygon against clipping window PQRS. The coordinates of polygon are A(80,
200), B(220, 120), C(150, 100), D(100, 30), E(10, 120). Coordinates of clipping window
P(200, 50), Q(50, 150), R(200, 150) & S(50, 50).
GauravBhattarai
GauravBhattarai
GauravBhattarai
Thank You
GauravBhattarai