Professional Documents
Culture Documents
Chapter 5
Chapter 5
“The process of selecting and viewing an image with different views, called windowing.” All the
objects in the real world have a size. We can measure the size and location of an object by the
unit.
For Example-We use the meter unit to measure both size and the location of the object.
When we represent the image of an object on the screen, then we use the screen coordinate
system. The screen coordinate system is used to define the location of the object. When we select
the screen coordinate system, then the image can be displayed on the screen. “The Capability to
show some part of an object in a window is known as windowing.” “The rectangular area
describes in the world coordinate system is called the window.”
Viewport:
“The viewport can be defined as an area on the screen which is used to display the object.” The
window is an area space for the object. Viewport surrounds the object. We need the coordinate
transformation to display the object on the screen. We can define many viewports on a different
area of the screen and also see the same object from a different angle in the viewport.
The object inside the clipping window is mapped to the viewport. The viewport is displayed
inside the interface window on the screen. We can use the clipping window to select the part of
an object, and the viewport is used to display the selected part of the object on the screen or
output device.
Steps for Window to Viewport Transformation: We can follow the following steps for
transform window to viewport:
Step 1: Translation of the window towards the Origin- If we shift the window towards the
origin, the upper left, and the lower-left corner of the window will be negative (-). The
translation factor also should be negative (-).
Step 2: Resize the window to viewport size- To Convert the size of the window into the size of
the viewport, we will use the following formulas:
Sx = XVmax – XVmin / XWmax – XWmin
Sy = YVmax – YVmin / YWmax – YWmin
Step 3: Translation of window (Position of window and viewport must be same)- If the
lower-left corner of viewport is (0, 0), then the window lower-left corner is already shifted on
origin after following step 1.
If the lower-left corner is not equal to (0, 0), then the translation factor should be positive (+).
It may be possible that sometimes the size of viewport is greater or smaller than the window. In
that situation, we have to enlarge or compress the size of the window according to the
viewport. We can perform it using some mathematical calculations.
For Coordinate x:
For Coordinate y:
Now, we get
1. We can select the world coordinate system according to the application program.
2. We can select the screen coordinate system according to the desired design.
3. Viewing transformation is a connection between the world and the screen coordinates.
Advantages:
We can easily represent images on the display screen according to the user’s needs.
Numerical exercise
1. Find normalization transformation that maps a window whose lower-left corner is at (1,1)
and upper right corner is at (3,5) onto:
A. Viewport with lower-left corner (0,0) and upper right corner (1,1)
B. Viewport with lower left corner (0,0) and upper right corner (1/2,1/2)
a) vxmin=0 , vymin=0
b) vxmin=0, vymin=0
Sx = 1-0/3-1 = 1/2 ,
Sy=1-0/5-1 = ¼
Panning
“Panning is a process or photographic technique that is used to combine slow shutter speed with
camera movement to make a speed sense around the moving object.”
We can define panning as a way to keep the main object in focus and blurring the background.
The word panning is derived from ‘panorama’ that indicates a broad view. In other words,
panning is a device used for constantly exposing and including off-screen space into the image.
If we talk about video technology, Panning is defined as horizontal scrolling of pictures expand
over the display. In 3D modeling, panning is referred as the parallel moving to view plane. The
camera moves perpendicular to the pointed direction. The image captured by the panning camera
is known as a panning shot.
Advantages of Panning
Inking:
“When we sample a graphical input device’s location at regular intervals and represent a point at
each sampled position, then a measure of the device’s motion will be shown. This technique is
sharply producing drawing on the paper, called inking.”
Use of inking:
Zooming Effect
Zooming Effect is Successively mapping different sized windows on a fixed size viewport. As
the windows are made smaller, so we zoom in on some part of a scene to view details that were
not visible in large windows. Also, We can obtain more overview by zooming out from a section
of a scene with successively larger windows.
Clipping
“The Clipping is a type of transformation used in computer graphics to remove lines, objects,
and segments of lines that are outside the computer screen or viewing pane.” The clipping is a
process of deciding the visible and invisible part of the image, object, or any line segment.
We only select the visible part and remove the invisible part of the line. The process clipping can
be used in two-dimensional and three-dimensional graphics.
In three-dimensional graphics, we can use the term clipping in many ways to define various
features. The clipping is a term that describes some operations that work in a three-dimensional
plane with rectangular shapes. We can extend the clipping to higher dimensionality. We can use
various methods and algorithms to increase the dimensionality of clipping.
Applications of clipping
We can perform various operations that correlate with the pointing of an object. For
example, delete, copy, insert, and moving selected parts of an object, etc.
Types of lines
The lines are divided into three types.
Visible Line: The line lying inside the view pane, is a visible line.
Invisible Line: The line lying outside the view pane, is an invisible line.
Clipped Line: “A line that lies inside or outside the window is called clipped line.” A
point where the line cut the view pane is known as the Intersection point of the line
Examples of Lines
There are some figures given below that represents the types of line.
We can use the clipping process with world coordinates. The object and images in view pane can
be mapped to device coordinates.
Types of clipping
We can divide clipping into following types-
1. Line clipping 3. Text clipping 5. Curve clipping
2. Point clipping 4. Exterior Clipping 6. Polygon clipping
In this algorithm, we will divide the view pane into nine equal segments (as shown in the
below figure) that only serve the viewport.
Now, we will represent the top, bottom, left, and right corner of the window with 4 bits.
This 4bit can be described with the following point that:
If an object lies within any particular corner position, that corner value will be 1, else it
will be 0.
The allocation of bits depends on “TBRL” (Top, Bottom, Right, Left) rule.
Suppose, if the point of a line appears in the top-left corner, then according to TBRL, the
value is 1001. We will allot the bits as-
For the top corner, because the object is present at the top corner.
For the bottom corner, because the object does not lie at the bottom.
For the right corner, because the object does not lie at the right side.
For the left corner, because the object lies at the top-left corner.
In this way, we check TBRL for each segment and allot the bits accordingly.
In Cohen- Sutherland Algorithm we will divide the lines into following Sections-
Visible Line: When both points (starting and ending) of the line are entirely situated
inside the window.
Invisible Line: When both points (Starting and ending) of the line are completely
situated outside the window.
If we have (xmin, xmax) and (ymin, ymax) coordinates of the view pane (window).
Then, it should be described as-
x0, x1 > xmax
y0, y1 > ymax
x0, x1 < xmin
y0, y1 < ymin
Clipped Line: Every line has two endpoints. Let (x0, y0) and (x1, y1) are points of the line. If
one point of the line situated inside the window and the other one is outside the window, then
the line is known as Clipped Line.
The algorithm was introduced by “You-Dong Liang” and “Brian A. Barsky.” It is used for line
clipping. It is a more powerful algorithm than the Cohen-Sutherland algorithm.
We use the following concepts in this algorithm-
These are used to describe the range of windows to find out the intersection points
between the line and the clipping window.
The parametric line is also known as “Cyrus-Beck.”
In this algorithm, we have to find the intersection point based on a time interval.
Time interval (t) can be defined as travelling time between initial position (0) to final
position (1). Then we have,
0 < t < 1 (Here, t lies between 0 and 1)
We have the formula to find x and y points of the line-
x= x1 + t. ?x (For point x)
y= y1 + t. ?y (For point y)
To check that the point lies between the window or outside the equation is-
Xwmin <= x1 + t. ?x <= Xwmax
Ywmin <= y1 + t. ?y <= Ywmax
These two conditions can be written as-
x1 + t. ?x >= Xwmin
x1 + t. ?x <= Xwmax
y1 + t. ?y >= Ywmin
y1 + t. ?y <= Ywmax
We can take a common expression for above four conditions. It will be-
t.pk <= qk (Here the value of k is multiple)
t = qk / pk
o p1 = -?x q1 = x1 - xwmin (For left boundary)
p2 = ?x q2 = xwmax - x1 (For right boundary)
p3 = -?y q3 = y1 - ywmin (For bottom boundary)
p4 = ?y q4 = ywmax – y1(For top Boundary)
pk < 0
then
t1 = max (0, qk / pk)
If
pk > 0
then
t2 = min (1, qk / pk)
Now, if t1 < t2 {If t1 value is changed
Then the first point is outside the window.
If t2 value is changed
Then the second point is outside the window}
else
t1 > t2
then
{Line is completely outside the window}
Step 6: Stop.
Example: Let a rectangular window size with (5, 9). The points of the line are (4, 12) and
(8, 8). Use the Liang- Barsky algorithm to clip the line and find the intersection point.
Solution:
We have, The initial point of the line (p1) = (4, 12)
The ending point of the line (p2) = (8, 8)
x1 = 4, x2 = 8
y1 = 12, y2 = 8
xwmin = 5, xwmax = 9
ywmin = 5, ywmax = 9
Step 1: We have to calculate the value of ?x and?y-
?x = x2- x1= 8-4 = 4
?y = y2- y1= 8-12 = -4
Step 2: Now, we will calculate-
p1 = -4 q1 = 4-5 = -1
p2 = 4 q2 = 9-4 = 5
p3 = 4 q3 = 12-5 = 7
p4 = -4 q4 = 9-12 = -3
Step 3: Now we will calculate t1 value-
If p1, p4 < 0
Then t1 =max (0, qk /pk)
=max (0, q1 /p1, q4 /p4)
=max (0, 1/4, 3/4)
t1 = 3/4
If p2, p3 > 0
Then t2 = min (1, qk /pk)
= min (1, q2 /p2, q3 /p3)
= min (1, 5/4, 7/4)
t2 = 1
Step 4: Now, we have to calculate the intersection point.
x = x1 + t1. ?x= 4+ 3/4 * 4 = 7
y = y1 + t1. ?y= 12+ 3/4 *(-4) = 9
The coordinates intersection point = (7, 9)
Step 1: Assign the bit code for both endpoints of the line.
Step 2: Now, implement OR operation on both endpoints of the line.
Step 3: If the OR = 0000,
Then
{The line is Visible}
Else
{Implement AND operation on endpoints}
Then
If AND ? 0000
Then
{The line is Invisible}
Else
Example: A window contains the size (0, 50, 0, 50). A line PQ has the coordinates (-10, 40) and
(30, -20). Find the visible point of the line using midpoint subdivision.
Solution: We have,
The coordinates for x and y = P (-10, 40)
The coordinates for x and y = Q (30, -20)
Now,
Step 1: We have to compute the midpoint of the line segment PQ.
Q = [(-10 + 30) /2, (40 - 20)/2]
= (10, 10)
Now the new coordinates of Q = (10, 10)
Step 2: Now, we will find
Q’’ = midpoint of the Q’ and Q
Q’’ = [(10 + 30) /2, (10 + (-20))/2]
= (20, -5)
Now the new coordinates of Q’’ = (20, -5)
Here (20, -5) is much better than (10, 10)
Now we have to find Q’’’ then,
Q’’’ = [(20 + 30) /2, (-5 + (-20))/2]
= (25, -12.5)
Now the new coordinates of Q’’’ = (25, -12.5)
We can clip the line from Q’’ to Q from the top side.
Step 3: Now, we will take left hand side part. The endpoints are P and Q’’’
We will find the midpoint of P and Q’’’
P (-10,40) and Q’’’ (25, -12.5)
P’ = [(-10 + 25) /2, (40 + (-12.5))/2]
Point Clipping
“Point clipping is a process which is used to define the point position.” The point is either inside
the view pane (window) or outside the view pane.
In computer graphics, the computer screen work like a two-dimensional coordinate system. Each
point does not need to be displayed inside the computer screen.
It includes two terms-
Window: It means what to display?
Clipping: It means discarding the portion that is outside the window.
Example: Let us have a view pane (window). The coordinates of the window are-
(xwmax, xwmin) - For X-axis of the window
Polygon Clipping
“A Polygon can be described as the enclosed collection or group of the lines.”
In a polygon, all lines are connected. Lines can be a combination of edges and vertices, which
together form a polygon. A polygon refers to a two-dimensional architecture made up of a
number of straight lines.
Some Examples of the polygon:
1. Triangles 3. Hexagons
2. Pentagons 4. Quadrilaterals
The polygon’s name defines how many sides the architecture contains.
Triangle: It has three sides.
Convex Polygon: The convex polygon has at least one part of diagonal in its exterior. In a
convex polygon, all the angles should be less than 180° (angle<180°).
Polygon Clipping
Polygon clipping is a process in which we only consider the part which is inside the view pane
or window. We will remove or clip the part that is outside the window. We will use the following
algorithms for polygon clipping-
Sutherland-Hodgeman polygon clipping algorithm
Weiler-Atherton polygon clipping algorithm
Sutherland-Hodgeman polygon clipping algorithm
The polygon clipping algorithm deals with four different clipping cases. The output of each case
is input for the next case.
Case1) Left clip: In the left side polygon clipping, we only remove the left part of the polygon,
which is outside the window. We only save the portion which is inside the window.
Case2) Right clip: In the right-side polygon clipping, we only remove the right part of the
polygon, which is outside the window. We only save the portion which is inside the window.
Case3) Top clip: On the top side polygon clipping, we only remove the top part of the polygon,
which is outside the window. We only save the portion which is inside the window.
Case4) Bottom clip: In the bottom side polygon clipping, we only remove the bottom part of the
polygon, which is outside the window. We only save the portion which is inside the window.
Condition 2(In-Out): If the first vertex of the polygon is inside and the second vertex is outside
the window, then the output will be the intersection point.
Condition 3(In-In): If both vertices of the polygon are inside the window, then the output will
be the second vertex.
Condition 4(Out-Out): If both vertices of the polygon are outside the window, then the output
will be nothing. It means we found a clipped polygon.
Iteration 2-
Review Exercise
1. Clip a line A (-1,5) and B (3,8) using the Cohen Sutherland algorithm with window coordinates (-
3,1) and (2,6).
2. Explain the concepts of clipping window, view port, display window, and their relations
in a viewing pipeline.
3. Suppose the eye position is at (0, 0, 1), the look-at point is at (0, 0, 0), the view up vector
is (0, 1, 0), and the view plane is z = -1. Given a point P(2, -10, -2), compute coordinates
of the perspective point of P on the view plane in the view coordinate system.
4. What transformations are used in graphic pipeline from model to screen?
5. We saw that a fundamental operation in graphics system is to map a point (x, y), which
lies within a clipping rectangle, to a point (xs, ys), which lies in the viewport of a window
on the screen. Assume that the two rectangles are defined by OpenGL function calls
glViewport(u, v, w, h);
gluOrtho2D(x_min, x_max, y_min, y_max);
Find the mathematical equations that map (x, y) into (xs, ys).
6. Consider a window that is bounded by these lines : y = 0; x = 0; y = 3 and x = 5. If
clipped against this window, the line segment joining the (-1, 0) and (4, 5) will connect
the points will be: