0% found this document useful (0 votes)
76 views106 pages

Cga Unit 2

This document discusses 2D transformations in computer graphics, including topics like translation, rotation, scaling, and their matrix representations. It also covers composite transformations, reflections, shearing, and 2D viewing concepts like the viewing pipeline and mapping world coordinates to device coordinates for display. The document is a set of lecture slides that were prepared by faculty at SRM Institute of Science and Technology to teach their 21CSE255T computer graphics and animation course.

Uploaded by

kiran sankar
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)
76 views106 pages

Cga Unit 2

This document discusses 2D transformations in computer graphics, including topics like translation, rotation, scaling, and their matrix representations. It also covers composite transformations, reflections, shearing, and 2D viewing concepts like the viewing pipeline and mapping world coordinates to device coordinates for display. The document is a set of lecture slides that were prepared by faculty at SRM Institute of Science and Technology to teach their 21CSE255T computer graphics and animation course.

Uploaded by

kiran sankar
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/ 106

SRM institute of Science and Technology

Chennai

21CSE255T - COMPUTER GRAPHICS AND ANIMATION

UNIT - II
2D TRANSFORMATIONS
Prepared by
Mr. S.Prabu
Mrs.G.Bhargavi
Assistant Professor(CTech)
SRMIST-KTR
UNIT-2
TOPICS

 Introduction to 2D Transformation  Clipping operations


 Basic Transformation  Point clipping

 Matrix representation  Line Clipping


 Cohen-Sutherland
 Composite Transformation
 Liang-Barsky
 Shear –Reflection
 Nicholl-Lee-Nicholl
 2D viewing
 Nonrectangular Line Clipping
 Viewing pipeline  Polygon Clipping
 Viewing functions.  Other Clipping methods
UNIT-2
2D TRANSFORMATION
 Introduction:
Changing Position, shape, size, or orientation of an object is known
as transformation
UNIT-2
2D TRANSFORMATION
 Definition:
“Transformations are the operations applied to geometrical
description of an object to change its position, orientation, or size
are called geometric transformations”.

 Transformation can be classified as


• Basic Transformation
• Other Transformation
UNIT-2
2D TRANSFORMATION
The Basic Transformations:
1. Translation
2. Scaling
3. Rotation

Other Transformations:
4. Reflection
5. Shearing
UNIT-2
2D TRANSFORMATION
• Translation
T(tx, ty) : Translation distances
• Scale
S(Sx,Sy) : Scale factors
• Rotation
R( Ø) : Rotation angle

These are known as basic transformation because with


combination of them we can obtain any transformatio
UNIT-2
TRANSLATION
 Translation is a process of changing the position of an object in
a straight-line path from one co- ordinate location to another.
 We can translate a 2Dpoint by adding translation distances, tx
and ty.
 Suppose the original position is (x ,y)
then new position is (x’, y’).
 Here x’=x + tx and y’=y + ty.
 The translation distance point (tx, ty) is called translation
vector or shift vector.
UNIT-2
TRANSLATION
• Translation equation can be expressed as single matrix equation by
using column vectors to represent the coordinate position and the
translation vector as

• We can also represent it in row vector form as:


UNIT-2
TRANSLATION
UNIT-2
TRANSLATION
Ex. Translate a polygon with co-ordinates A(2,5) B(7,10) and
C(10,2) by 3 units in X direction and 4 units in Y direction.
UNIT-2
ROTATION
 Rotation is applied to an object by repositioning it along a circular
path on xy plane.
 To generate a rotation, specify a rotation angle θ and the position
(xr,yr) of the rotation point (pivot point)

+ve rotation angle defines counter clockwise rotation.


-ve rotation angle defines clockwise rotation.
UNIT-2
ROTATION
 We first find the equation of rotation when pivot point is at coordinate
origin(0,0).
 From figure we can write.
UNIT-2
ROTATION
 Now replace 𝒓 𝐜𝐨𝐬 ∅ with 𝒙 and 𝒓 𝐬𝐢𝐧 ∅ with 𝒚 in above equation.

column vector matrix equation are,


UNIT-2
ROTATION
UNIT-2
SCALING
 Transformation that used to alter the size of an object is known as
scaling.
 This operation is carried out by multiplying coordinate value (𝒙, 𝒚)
with scale factors (𝒔𝒙, 𝒔) respectively.
 Equation for scaling is given by

 These equation can be represented in column vector matrix


equation as
UNIT-2
SCALING
 Normal scaling will scale as well as reposition the object.
 Scale factors less than 1 reduce the size and move object closer to
origin.
 Scale factors greater than 1 enlarge the size of object and move object
away from origin.
 Example scale square with opposite corner coordinate point are (1, 1)
and (2, 2) by scale factor (3, 3)
UNIT-2
SCALING
 Same values of 𝒔𝒙 and 𝒔𝒚 will produce Uniform Scaling.
 Different values of 𝒔𝒙 and 𝒔 will produce Differential (Non
Uniform) Scaling.
UNIT-2
MATRIX REPRESENTATION & HOMOGENEOUS
CO-ORDINATES
 Many graphics application involves sequence of geometric
transformations.
 For efficient processing we will reformulate transformation
sequences.
 We have matrix representation of basic transformation and we
can express it in the general matrix form as
where
UNIT-2

HOMOGENEOUS MATRIX FOR TRANSLATION

 Let’s see each representation with 𝒉 = 𝟏

Inverse of translation matrix is obtain by putting −𝒕𝒙 & −


instead of 𝒕𝒙 & 𝒕𝒚
UNIT-2

HOMOGENEOUS MATRIX FOR ROTATION

Inverse of rotation matrix is obtained by replacing 𝜽 by −𝜽.


UNIT-2

HOMOGENEOUS MATRIX FOR SCALING

Inverse of scaling matrix is obtained by replacing 𝒔𝒙 & y


UNIT-2
COMPOSITE TRANFORMATION
 In practice we need to apply more than one transformations to
get desired result.
 It is time consuming to apply transformation one by one on
each point of object.
 So first we multiply all matrix of required transformations which
is known as composite transformation matrix.
 Than we use composite transformation matrix to transform
object.
 For column matrix representation, we form composite
transformations by multiplying matrices from right to left.
UNIT-2
COMPOSITE TRANSLATION
 Two successive translations are performed as:
UNIT-2
COMPOSITE TRANSLATION

 Here 𝑷 ′ and 𝑷 are column vector of final and initial point coordinate
respectively.
 This concept can be extended for any number of successive
translations.
UNIT-2
COMPOSITE ROTATION
 Two successive Rotations are performed as
UNIT-2
COMPOSITE ROTATION

 Here 𝑷 ′ and 𝑷 are column vector of final and initial point coordinate
respectively.
 This concept can be extended for any number of successive rotations
UNIT-2
COMPOSITE SCALING
 Two successive Scalings are performed as
UNIT-2
COMPOSITE SCALING

 Here 𝑷 ′ and 𝑷 are column vector of final and initial point coordinate
respectively.
 This concept can be extended for any number of successive scaling
UNIT-2
OTHER TRANSFORMATION

 Some package provides few additional transformations which

are useful in certain applications.


 Two such transformations are:

1. Reflection
2. Shear
UNIT-2
REFLECTION
 A reflection is a transformation that produces a mirror image of
an object.
 The mirror image for a two –dimensional reflection is generated
relative to an axis of reflection by rotating the object 180o about
the reflection axis.
 Reflection gives image based on position of axis of reflection.
Transformation matrix for few positions are discussed here
UNIT-2
REFLECTION About an X axis
 For reflection about the line
𝒚 = 𝟎 , 𝒕𝒉𝒆 𝒙 𝒂𝒙𝒊𝒔
 Transformation matrix:

 This transformation keeps 𝑥 values are same, but flips (Change the
sign) 𝑦 values of coordinate positions.
UNIT-2
REFLECTION About an Y axis
 For reflection about the line
x = 𝟎 , 𝒕𝒉𝒆 y 𝒂𝒙𝒊𝒔
 Transformation matrix:

 This transformation keeps 𝑦 values are same, but flips (Change the
sign) 𝑥 values of coordinate positions.
UNIT-2
REFLECTION About Origin

 For reflection about the 𝑶𝒓𝒊𝒈𝒊𝒏.


 Transformation matrix:

 This transformation flips (Change the sign) 𝑥 and 𝑦 both values of


coordinate positions.
UNIT-2
SHEAR TRANSFORMATION
 A transformation that distorts the shape of an object such that the
transformed shape appears as if the object were composed of
internal layers that had been caused to slide over each other is
called shear.

 Two common shearing transformations are those that shift


coordinate 𝑥 values and those that shift 𝑦 values
UNIT-2
SHEAR in X Direction
 Shear relative to 𝑥 − 𝑎𝑥𝑖𝑠 that is 𝑦 = 0 line can be produced by
following equation: 𝒙 ′ = 𝒙 + 𝒔𝒉𝒙 ∙ 𝒚 , 𝒚′=𝒚
 Transformation matrix for that is

 Here 𝒔𝒉𝒙 is shear parameter.


 We can assign any real value to 𝒔𝒉𝒙.
UNIT-2
SHEAR in Y Direction
 Shear relative to 𝑦 − 𝑎𝑥𝑖𝑠 that is 𝑥 = 0 line can be produced by
following equation: 𝒙 ′ = 𝒙 , 𝒚 ′ = 𝒚 + 𝒔𝒉𝒚 ∙ 𝒙
 Transformation matrix for that is

 Here 𝒔𝒉𝒚 is shear parameter.


 We can assign any real value to 𝒔𝒉𝒚.
UNIT-2
2D VIEWING

2D viewing is a technique to map the world coordinates system (actual


coordinates of the object in the real world) to device coordinates (actual
coordinates of the object on the output screen like a monitor).
UNIT-2
VIEWING PIPELINE

 A world coordinate area selected for display is called a window


 An area on a display device to which a window a mapped is called a
view port
 The window defines what is to be viewed
 The viewport defines where it is to be displayed
 The mapping of a part of a world coordinate scene to device
coordinates is referred to as a viewing transformation.
UNIT-2
VIEWING PIPELINE
 Window to Viewport Transformation is the process of transforming 2D
world-coordinate objects to device coordinates.
 Objects inside the world or clipping window are mapped to the viewport
which is the area on the screen where world coordinates are mapped to
be displayed.
UNIT-2
WINDOW TO VIEWPORT TRANSFORMATION
 A point at position (xw,yw) in a designated window is mapped to
viewport coordinates (xv,yv) so that relative positions in the two
areas are the same.
 The figure illustrates the window to view port mapping.
 A point at position (xw,yw) in the window is mapped into position
(xv,yv) in the associated view port.
 To maintain the same relative placement in view port as in
window.
UNIT-2
WINDOW TO VIEWPORT TRANSFORMATION
UNIT-2
WINDOW TO VIEWPORT TRANSFORMATION
 The window to viewport coordinate transformation is known as
workstation transformation.
 It is achieved by the following steps
1.The object together with its window is translated until the lower
left corner of the window is at the orgin.
2.Object and window are scaled until the window has the
dimensions of the viewport
3.Translate the viewport to its correct position on the screen.
 The relation of the window and viewport display is expressed as
XV- XVmin XW-XWmin
UNIT-2
VIEWING FUNCTION
 We define a viewing reference system in a PHIGS application
program with the following function:
evaluateViewOrientationMatrix (x0, y0, xv, yv, error, viewMatrix)

 where parameters x0 and y0 are the coordinates of the viewing


origin, and parameters xv and yv are the world-coordinate
positions for the view up vector.

 An integer error code is generated if the input parameters are in


error; otherwise, the view matrix for the world-to-viewing
transformation is calculated.
UNIT-2
VIEWING FUNCTION
 To set up the elements of a window-to-viewport mapping matrix,
we invoke the function
evaluateViewMappingMatrix (xwmin, xwmax, ywmin, ywmax,
xvmin, xvmax, yvmin, yvmax, error, viewMatrix)

 we can store combinations of viewing and window-viewport


mappings for various workstations in a viruing table with

setVlewRepresentation (ws, viewIndex, viewMatrlx, viewMapping


Matrix, xclipmin, xclipmax, yclipmin, yclipmax, clipxy)
UNIT-2
VIEWING FUNCTION
 To set up the elements of a window-to-viewport mapping matrix,
we invoke the function
evaluateViewMappingMatrix (xwmin, xwmax, ywmin, ywmax,
xvmin, xvmax, yvmin, yvmax, error, viewMatrix)

 we can store combinations of viewing and window-viewport


mappings for various workstations in a viruing table with

setVlewRepresentation (ws, viewIndex, viewMatrlx, viewMapping


Matrix, xclipmin, xclipmax, yclipmin, yclipmax, clipxy)
UNIT-2
VIEWING FUNCTION
 selects a particular set of options from the viewing table.
setViewIndex(viewIndex)

 At the find stage, we apply a workstation transformation by selecting


a workstation window-viewport pair:
setWorkstationWindow (ws, xwsWindmin, xwsWindmax, ywsWindmin,
ywsWindmax)

setWorkstationViewport (ws, xwsVPortmin, xwsVPortmax, ywsVPortmin,


ywsVPortmax)
UNIT-2
CLIPPING OPERATIONS
 Definition:
“Any procedure that identifies those positions of picture is
either inside or outside of a specified reason of space” is
referred to as clipping algorithm or simply clipping.

• For the viewing transformation we want to display only those


picture parts that are within the window.

• Everything the outside the window is discarded.


UNIT-2
CLIPPING OPERATIONS
 Clip Window:
“The region against which an object is to be clipped” is called a
clip window.

• The complete world-coordinate picture can be mapped first to


device coordinates, or normalized device coordinates, then clipped
against the viewport boundaries.
UNIT-2
CLIPPING OPERATIONS
Types
 There are number of clipping algorithm are used.
 Point Clipping
 Line Clipping
 Polygon Clipping
 Curve Clipping
 Text Clipping
UNIT-2
POINT CLIPPING
Definition:
"To determine whether a point(x,y) lies inside or outside a specific
region or boundary" is referred to as Point Clipping

Steps:
 Get the minimum and maximum coordinates of both viewing pane.
 Get the coordinates for a point.
 Check whether given input lies between minimum and maximum
coordinate of viewing pane.
 If yes display the point which lies inside the region otherwise
discard it.
UNIT-2
POINT CLIPPING
"To determine whether a point lies inside or outside a specific region or boundary”

Conditions to be checked
x ≤ xmax
x ≥ xmin
y ≤ ymax
y ≥ ymin
UNIT-2
LINE CLIPPING
Definition:
"The process of removing (clipping) lines or portions of lines outside
an area of interest (a viewport)"

Steps:
 Check the line completely inside the clipping window.
 If no, Check the line completely outside the clipping window.
 if both are no, perform intersection calculations with one or more
clipping boundaries.
UNIT-2
LINE CLIPPING
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING
• It divides a two-dimensional space into 9 regions and then
efficiently determines the lines and portions of lines that are inside
the given rectangular area.

Steps:
 Check the line completely inside the clipping window.
 If no, Check the line completely outside the clipping window.
 if both are no, perform intersection calculations with one or more
clipping boundaries.
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING
Region Code
• Every line endpoint in a picture is assigned a four digit binary
code called a region code.

• The central part is the viewing region or window, all the lines which
lie within this region are completely visible.

• A region code is always assigned to the endpoints of the given line.


UNIT-2
COHEN SOUTHERLAND LINE CLIPPING

1 0 0 1

Bit 1 : Left

Bit 2 : Right

Bit 3 : Bottom

Bit 4 : Top
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING

Bit1 is set to 1 if x <xwmin


bit 2 is set to 1 if xwmax < x
bit 3 is set to 1 if y <ywmin
bit 4 is set to 1 if ywmax < y.
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING

Bit1 is set to 1 if x <xwmin


bit 2 is set to 1 if xwmax < x
bit 3 is set to 1 if y <ywmin
bit 4 is set to 1 if ywmax < y.
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING
There are three possible cases for any given line.
 Completely inside the window : No Clipping
 Completely outside the window : Clipping the entire line

 Partially inside the window : Find Intersection, and clip the


outer portion of the line
UNIT-2
COHEN SOUTHERLAND LINE CLIPPING
UNIT-2
LIANG-BARSKY LINE CLIPPING
• The Liang–Barsky algorithm uses the parametric equation of a line
and inequalities describing the range of the clipping window to
determine the intersections between the line and the clip window.

• With these intersections it knows which portion of the line should


be drawn.

• The parametric equation of a line can be given by,


x = x1 + t(x2-x1)
Y = y1 + t(y2-y1)
UNIT-2
LIANG-BARSKY LINE CLIPPING
• Where, t is between 0 and 1. Then, writing the point-clipping
conditions in the parametric form:
xwmin <= X <= xwmax
ywmin <= Y <= ywmax

• The above 4 in equations can be expressed as,

tpk <= qk
UNIT-2
LIANG-BARSKY LINE CLIPPING
• Where, parameter p & q are defined as :

p1 = -∆x q1 = x1 – xwmin
p2 = ∆x q2 = xwmax – x1
p3 = -∆y q3 = y1 – ywmin
p4 = ∆y q4 = ywmax – y1
UNIT-2
LIANG-BARSKY LINE CLIPPING
• Following observations can be:
• pk = 0 ; Line is parallel to the window.
• qk < 0 ; Line is completely outside the window.
• pk < 0 ; Line is proceeds from outside to inside the window.
• pk > 0 ; Line is proceeds from inside to outside the window.

• i.e Line intersect the clipping booundary


UNIT-2
LIANG-BARSKY LINE CLIPPING
• Calculate the parameter t=qk/pk for k=1,2,3,4.
• When pk<0, select the maximum values of qk/pk
• When pk>0, select the minimum values of qk/pk

• If t1<t2 , then calculate the intersection points as:


• xx1 = x1 + t1 * ∆x
• yy1 = y1 + t1 * ∆y
• xx2 = x1 + t2 * ∆x
Draw the clipped line ((xx1 , yy1) , (xx2 , yy2) )
• yy2 = y1 + t2 * ∆y
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• These multiple intersection calculation is avoided in NLN line
clipping procedure.
• By creating more regions around the clip window the NLN
algorithm avoids multiple clipping of an individual line segment.
• NLN line clipping perform the fewer comparisons and divisions so
it is more efficient.
• But NLN line clipping cannot be extended for three dimensions.
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• For given line we find first point falls in which region out of nine
region shown in figure.
• Only three region are considered which are.
• Window region
• Edge region
• Corner region
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• If point falls in other region than we transfer that point in one of the
three region by using transformations.
• We can also extend this procedure for all nine regions.
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• Based on position of first point out of three region highlighted we
divide whole space in new regions.

• Regions are name in such a way that name in which region p2 falls
is gives the window edge which intersects the line.

• 𝑝1is in window region(P1 is inside clipping boundary)


UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• 𝑝1 is in Corner region (one of the two possible sets of region can be
generated)
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
Finding Region of Given Line in NLN
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
• After checking slope condition we need to check weather it crossing
zero, one or two edges.
• This can be done by comparing coordinates of 𝑝2 with coordinates of
window boundary.
• For left and right boundary we compare 𝑥 coordinates and for top and
bottom boundary we compare 𝑦 coordinates.
• If line is not fall in any defined region than clip
entire line.
• Otherwise calculate intersection.
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
Intersection Calculation in NLN
UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
Intersection Calculation in NLN
• After finding region we calculate intersection point using parametric
equation which are:

• For left or right boundary 𝑥 = x1 or xr respectively, with


t = (x1/r - x1) / (x2 - x1) , so that y can be obtain from parametric
equation as below.

• Keep the portion which is inside and clip the rest.


UNIT-2
NICHOLL-LEE-NICHOL LINE CLIPPING
Intersection Calculation in NLN
• Similarly for top or bottom boundary y = yt or yb respectively, and
t = (yt/b - y1) / (y2 - y1) , so that we can calculate 𝑥 intercept as
follow:
UNIT-2
NON RECTANGULAR LINE CLIPPING
• In some applications, it is often necessary to clip lines against
arbitrarily shaped polygons.

• Algorithms based on parametric line equations, such as the Liang-


Barsky method can be extended easily convex polygon windows.

• We do this by modifying the algorithm to include the parametric


equations for the boundaries oi the clip region.
UNIT-2
NON RECTANGULAR LINE CLIPPING
• Circles or other curved-boundary clipping regions are also possible.
• But less commonly used.

• They are slower because intersection calculations involve nonlinear


curve equations.

• At the first step, lines can be clipped against the bounding rectangle.

• Lines that can be identified as completely outside the bounding


rectangle are discarded.
UNIT-2
NON RECTANGULAR LINE CLIPPING
• To identify inside lines, we can calculate the distance of line
endpoints from the circle center.

• If the square of this distance for both endpoints of a line is less than
or equal to the radius squared, we can save the entire line.

• The remaining lines arc then processed through the intersection


calculations, which must solve simultaneous circle-line equations
UNIT-2
NON RECTANGULAR LINE CLIPPING
Splitting Concave Polygons
• We can identify a concave polygon by calculating the cross products
of successive edge vectors in order around the polygon perimeter.

• If the z component of some cross products is positive while others


have a negative z component, we have a concave polygon.

• Otherwise, the polygon is convex.


UNIT-2
NON RECTANGULAR LINE CLIPPING
Splitting Concave Polygons
• This is assuming that no series of three successive vertices are
collinear, in which case the cross product of the two edge vectors
for these vertices is zero.
• If all vertices are collinear, we have a degenerate polygon (a straight
line).
• The Figure(in next slide) illustrates the edge vector cross-product
method for identifying concave polygons.
UNIT-2
NON RECTANGULAR LINE CLIPPING
UNIT-2
SPLITTING CONCAVE POLYGONS
Vector Method
• A vector method for splitting a concave polygon in the xy plane is
to calculate the edge-vector cross products in a counter clockwise
order.
• And note the sign of the z component of the cross products.
• If any z component turns out to be negative (as in Fig. Previous
slide), the polygon is concave and we can split it along the line of
the first edge vector in the crossproduct pair.
UNIT-2
SPLITTING CONCAVE POLYGONS
• The figure shows a concave polygon with six edges.
UNIT-2
SPLITTING CONCAVE POLYGONS
• Edge vector for this polygon can be expressed as
UNIT-2
SPLITTING CONCAVE POLYGONS
• Where the z component is 0, since all edges are in the xy plane.
• The cross product EixEj for two successive edge vectors is a vector
perpendicular to the xy plane with z component equal to
EixEjy - EjxEiy
UNIT-2
SPLITTING CONCAVE POLYGONS

• Since the cross product E2 X E3 has a negative z component, we split


the polygon along the line of vector E2.
• The line equation for this edge has a slope of 1 and a y intercept of -1.
• We then determine the intersection of this line and the other polygon
edges to split the polygon into two pieces.
• No other edge cross products are negative, so the two new polygons
are both convex.
UNIT-2
SPLITTING CONCAVE POLYGONS

• Splitting a concave polygon using the rotational


method.

• After rotating V3 onto the x axis, we find that V4,


is below the x axls.

• So we split the polygon along the line of V2 V3


UNIT-2
POLYGON CLIPPING
• To clip polygons, we need to modify the line-clipping procedures.
• A polygon boundary processed with a line clipper may be displayed as
a series of unconnected line segments depending on the orientation of
the polygon to the clipping window.
UNIT-2
POLYGON CLIPPING
• For polygon clipping, we require an algorithm that will generate one or
more closed areas that are then scan converted for the appropriate area fill.
• The output of a polygon clipper should be a sequence of vertices that
defines the clipped polygon boundaries.
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• We can correctly clip a polygon by processing the polygon boundary as a


whole against each window edge.
• This could be accomplished by processing all polygon vertices against
each clip rectangle boundary in turn.
• Beginning with the initial set of polygon vertices, we could first clip the
polygon against the left rectangle boundary to produce a new sequence of
vertices.
• The new set of vertices could then k successively passed to a right
boundary
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• The new set of vertices could then k successively passed to a right


boundary clipper, a bottom boundary clipper, and a top boundary clipper,
as in Fig.
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• At each step, a new sequence of output vertices is generated and


passed to the next window boundary clipper.

• There are four possible cases when processing vertices in sequence


around the perimeter of a polygon.

• As each pair of adjacent polygon vertices is passed to a window


boundary clipper, we make the following tests:
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• 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.
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• If both input vertices are inside the


window boundary, only the second
vertex is added to the output vertex
list.
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• If the first vertex is inside the window


boundary and the second vertex is
outside, only the edge intersection
with the window boundary is added to
the output vertex list.
UNIT-2
SUTHERLAND-HODGEMAN POLYGON CLIPPING

• If both input vertices are outside the


window boundary, nothing is added to
the output list.
UNIT-2
OTHER CLIPPING METHODS

• Various parametric line-clipping methods have also been


adapted to polygon clipping. And they are particularly well
suited for clipping against convex polygon clipping windows.
• Curve Clipping
• Text Clipping
UNIT-2
CURVE CLIPPING

• Areas with curved boundaries can be clipped with methods


similar to those discussed in the line clipping.
• Curve-clipping procedures will involve nonlinear equations,
however, and this requires more processing than for objects
with linear boundaries.
• The bounding rectangle for a circle or other curved object can
be used first to test for overlap with a rectangular clip window.
UNIT-2
CURVE CLIPPING

• 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.
• In either case, there is no further computation necessary.
• For a circle, we can use the coordinate extents of individual
quadrants and then octants for preliminary testing before calculating
curve-window intersections.
• For an ellipse, we can test the coordinate extents of individual
quadrants.
UNIT-2
CURVE CLIPPING
• Following figure illustrates circle clipping against a rectangular
window.
UNIT-2
TEXT CLIPPING

• 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.
• In either case, there is no further computation necessary.
• For a circle, we can use the coordinate extents of individual
quadrants and then octants for preliminary testing before calculating
curve-window intersections.
• For an ellipse, we can test the coordinate extents of individual
quadrants.
UNIT-2
TEXT CLIPPING
• The simplest method for processing character strings relative to a
window boundary is to use the all-or-none string-clipping strategy
shown in Fig.
UNIT-2
TEXT CLIPPING
• An alternative to rejecting an entire character string that overlaps a
window boundary is to use the all-or-none character-clipping
strategy.
• Here we discard only those characters that are not completely inside
the window.
UNIT-2
TEXT CLIPPING
• Final method is to clip the components of individual characters.
• We now treat characters in much the same way that we treated lines.
• If an individual character overlaps a clip window boundary, we clip
off the parts of the character that are outside the window.

You might also like