CG Module 4 2D Viewing and Clipping
CG Module 4 2D Viewing and Clipping
Module - 4
Two-Dimensional Viewing and Clipping
CSC305
Objective
To emphasize on implementation aspect of Computer Graphics
Algorithms.
Outcome
At the end of the course student will be able to:
apply line and polygon clipping algorithms on 2D graphical objects.
Two-Dimensional Viewing and Clipping
Viewing Transformation
The process of selecting and viewing the picture with different views
is called windowing.
A process which divides each element of the picture into its visible
and invisible portions, allowing the invisible portion to be discarded
is called clipping.
The picture is stored in the computer memory using world
coordinate system.
The picture is displayed on the display device it is measured in
physical device coordinate system.
The viewing transformation which maps picture coordinates in the
WCS to display coordinates in PDCS is performed by the the
transformation -
• Normalization transformation(N)
• Workstation transformation(W)
Normalization Transformation
To make our programs to be device independent,
• we define the picture coordinates in some units other than pixels.
• we use the interpreter to convert these coordinates to appropriate
pixel values for the particular display device.
The device independent units are called the normalized device
coordinates.
Normalization Transformation
The interpreter uses a simple linear formula to convert the
normalized device coordinates to the actual device coordinates.
x = xn * xw
y = yn * y w
Where, x = Actual device x-coordinate
y = Actual device y-coordinate
xn = Normalized x-coordinate
yn = Normalized y-coordinate
xw = Width of actual screen in pixels.
yw = Height of actual screen in pixels.
The transformation which maps the world coordinates to normalized
device coordinate is called normalization transformation.
Workstation Transformation
An area selected in world coordinate system is called WINDOW.
Window defines what is to be viewed.
An area on a display on a device to which a window is mapped is
called a VIEWPORT.
Viewport defines where it is to be displayed.
Workstation Transformation
The window define in world coordinates is first transformed into the
normalized device coordinates.
The normalized window is then transformed into the viewport
coordinates.
This window to viewport coordinate transformation is known as
workstation transformation.
The viewing transformation is the combination of normalization
transformation and workstation transformations -
V = N. W
Window to Viewport Transformation
Steps -
• The object together with its window is translated until the lower
left corner of the window is at the origin.
• Object and window are scaled until the window has the
dimensions of the viewport.
• Translate the viewport to its correct position on the screen.
Window to Viewport Transformation
workstation transformation is given as
W = T . S . T-1
1 0 0
T= 0 1 0
- xwmin - ywmin 1
sx 0 0
S= 0 sy 0
0 0 1
T-1 = 0 1 0
xvmin yvmin 1
The overall transformation matrix for W is given as
W = T . S . T-1
sx 0 0
W= 0 sy 0
0.25 0 0
W= 0 0.125 0
- 0.25 - 0.125 1
2D Clipping
The procedure that identifies the portions of a picture that are either
inside or outside of a specified region of space is referred to as
clipping.
The region against which an object is to be clipped is called clip
window or clipping window.
Line Clipping
Consider the line segment with endpoints A(x1, y1) and B(x2, y2)
1. Any point p(x, y) is inside the window if all the following
inequalities are satisfied -
xwmin ≤ x ≤ xwmax
ywmin ≤ y ≤ ywmax
2. If both the endpoints of a line segment are within the window then
the line segment is visible.
3. If the line segment satisfies any one of the following condition
then the line segment is not visible.
x1, x2 < xwmin
x1, x2 > xwmax
y1, y2 < ywmin
y1, y2 > ywmax
Line Clipping
4. If the line segment is neither of category 2 or 3, then it is a
clipping candidate.