0% found this document useful (0 votes)
15 views

Computer Graphics Unit IV

This document discusses various topics related to computer graphics including: - Window to viewport transformation which maps a scene to device coordinates - Clipping techniques like line and polygon clipping which remove objects outside the viewing area - Cohen-Sutherland and Sutherland-Hodgman algorithms for line and polygon clipping respectively which determine the visible portions of lines and polygons within the viewing window.

Uploaded by

Akhil Sudheer
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)
15 views

Computer Graphics Unit IV

This document discusses various topics related to computer graphics including: - Window to viewport transformation which maps a scene to device coordinates - Clipping techniques like line and polygon clipping which remove objects outside the viewing area - Cohen-Sutherland and Sutherland-Hodgman algorithms for line and polygon clipping respectively which determine the visible portions of lines and polygons within the viewing window.

Uploaded by

Akhil Sudheer
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

Computer Graphics

Unit IV
Window to Viewport Transformation,
Clipping,
Line Clipping,
Cohen Sutherland Line Clipping,
Polygon Clipping,
Sutherland and Gray Hodgman
Polygon Clipping Algorithm.
• In geometry, a coordinate system is a system
that uses one or more numbers, or coordinates,
to uniquely determine the position of
the points or other geometric elements on
a manifold such as Euclidean space.
• Example:
– Number line system
– Cartesian coordinate system
• Cartesian coordinate system
– In the plane, two perpendicular lines are chosen and the
coordinates of a point are taken to be the signed
distances to the lines.

– In three dimensions, three mutually orthogonal planes


are chosen and the three coordinates of a point are the
signed distances to each of the planes.

– Depending on the direction and order of the coordinate


axes, the three-dimensional system may be a right-
handed or a left-handed system.
• World coordinate system (WCS) is the right handed cartesian
co-ordinate system where we define the picture to be
displayed. A finite region in the WCS is called the Window.
• A world-coordinate area selected for display is called a
window.
• In computer graphics terminology, the term window
originally referred to an area of a picture that is selected for
viewing. A Window is a rectangular region in the world
coordinate system.
• An area on a display device to which a window is mapped is
called a viewport.
Window to Viewport Transformation
• In general, the mapping of a part of a world-
coordinate scene to device coordinates is
referred to as a viewing transformation.
• Sometimes the two-dimensional viewing
transformation is simply referred to as the
window-to-viewport transformation
or the windowing transformation.
Window to Viewport Transformation
Window to Viewport Transformation
Window to Viewport Transformation
Window to Viewport Transformation
Clipping
• When a window is "placed" on the world, only
certain objects and parts of objects can be seen.
Points and lines which are outside the window are
"cut off" from view. This process of "cutting off"
parts of the image of the world is called Clipping.

• The primary use of clipping in computer graphics is


to remove objects, lines, or line segments that are
outside the viewing pane.
Clipping
• In clipping, we examine each line to determine
whether or not it is completely inside the window,
completely outside the window, or crosses a window
boundary. If inside the window, the line is displayed.
If outside the window, the lines and points are not
displayed. If a line crosses the boundary, we must
determine the point of intersection and display only
the part which lies inside the window.
Clipping
Line Clipping
• In computer graphics, line clipping is the process
of removing lines or portions of lines outside an
area of interest. Typically, any line or part
thereof which is outside of the viewing area is
removed.
• There are two common algorithms for line
clipping: Cohen–Sutherland and
Liang–Barsky.
Line Clipping
• A line-clipping method consists of various parts.
Tests are conducted on a given line segment to find
out whether it lies outside the view volume.
Afterwards, intersection calculations are carried out
with one or more clipping boundaries.
• Determining which portion of the line is inside or
outside of the clipping volume is done by processing
the endpoints of the line with regards to the
intersection.
Cohen Sutherland Line Clipping
• In computer graphics, the Cohen–Sutherland
algorithm is a line-clipping algorithm. The algorithm
divides a 2D space into 9 regions, of which only the
middle part (viewport) is visible.
• This algorithm uses the clipping window as shown in
the following figure. The minimum coordinate for the
clipping region is (XWmin,YWmin) and the maximum
coordinate for the clipping region is (XWmax,YWmax).
Cohen Sutherland Line Clipping
Cohen Sutherland Line Clipping
• We will use 4-bits to divide the entire region. These 4
bits represent the Top, Bottom, Right, and Left of the
region as shown in the following figure. Here,
the TOP and LEFT bit is set to 1 because it is the TOP-
LEFT corner.
Cohen Sutherland Line Clipping
• There are 3 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)
Cohen Sutherland Line Clipping
• Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
Step 3.2.1 − Choose an endpoint of the line that is outside the
window.
Step 3.2.2 − Find the intersection point at the window boundary
base on region code.
Step 3.2.3 − Replace endpoint with the intersection point and update the
region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially
accepted or trivially rejected.
Step 4 − Repeat step 1 for other lines.
Polygon Clipping
• Set of connected lines are considered as polygon;
polygons are clipped based on the window and the
portion which is inside the window is kept as it is
and the outside portions are clipped. The polygon
clipping is required to deal different cases. Usually
it clips the four edges in the boundary of the clip
rectangle
Polygon Clipping
• The clip boundary determines the visible and
invisible regions of polygon clipping and it is
categorized as four.
– Visible region is wholly inside the clip window – saves
endpoint
– Visible exits the clip window – Save the interaction
– Visible region is wholly outside the clip window –
nothing to save
– Visible enters the clip window – save endpoint and
intersection
Sutherland and Gray Hodgman
Polygon Clipping Algorithm
• A polygon can also be clipped by specifying the
clipping window. Sutherland Hodgeman polygon
clipping algorithm is used for polygon clipping. In
this algorithm, all the vertices of the polygon are
clipped against each edge of the clipping window.
Sutherland and Gray Hodgman
Polygon Clipping Algorithm
• First the polygon is clipped against the left edge
of the polygon window to get new vertices of the
polygon. These new vertices are used to clip the
polygon against right edge, top edge, bottom
edge, of the clipping window as shown in the
following figure.
Sutherland and Gray Hodgman
Polygon Clipping Algorithm
• Input :
– Polygon : (100,150), (200,250), (300,200)
– Clipping Area : (150,150), (150,200), (200,200),
(200,150) i.e. a Square
• Output : (150, 162) (150, 200) (200, 200) (200, 174)
// Implements Sutherland–Hodgman algorithm

void suthHodgClip(int poly_points[][2], int poly_size,


int clipper_points[][2], int clipper_size) {
//i and k are two consecutive indexes
for (int i=0; i<clipper_size; i++) {
int k = (i+1) % clipper_size;
// We pass the current array of vertices, it's size
// and the end points of the selected clipper line
clip(poly_points, poly_size, clipper_points[i][0],
clipper_points[i][1], clipper_points[k][0],
clipper_points[k][1]);
} // Printing vertices of clipped polygon
for (int i=0; i < poly_size; i++)
cout << '(' << poly_points[i][0] << ", " << poly_points[i][1] << ") ";
}

You might also like