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

5CS4-04 U3

The document discusses various types of transformations in computer graphics including translation, rotation, scaling, reflection, shearing, and their matrix representations. It introduces homogeneous coordinates which allow representing 2D points with 3 coordinates (x, y, w) instead of 2, enabling complex composite transformations to be performed with single matrix multiplications by combining translations, rotations, and scaling. Key topics covered include the rotation matrix, scaling matrix, translation vector, and transformation matrices for reflection and shearing. Homogeneous coordinates are used to combine multiple transformations like translation, rotation, translation into a single transformation.

Uploaded by

n9166254105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

5CS4-04 U3

The document discusses various types of transformations in computer graphics including translation, rotation, scaling, reflection, shearing, and their matrix representations. It introduces homogeneous coordinates which allow representing 2D points with 3 coordinates (x, y, w) instead of 2, enabling complex composite transformations to be performed with single matrix multiplications by combining translations, rotations, and scaling. Key topics covered include the rotation matrix, scaling matrix, translation vector, and transformation matrices for reflection and shearing. Homogeneous coordinates are used to combine multiple transformations like translation, rotation, translation into a single transformation.

Uploaded by

n9166254105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Unit 3 B.Tech.

– V Semester Computer Graphics and Multimedia

Lecture 13
Transformations (translation, rotation, scaling), matrix representation
Transformation means changing some graphics into something else by applying rules. We
can have various types of transformations such as translation, scaling up or down, rotation,
shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.
Transformations play an important role in computer graphics to reposition the graphics on
the screen and change their size or orientation.
Homogenous Coordinates
To perform a sequence of transformation such as translation followed by rotation and
scaling, we need to follow a sequential process −
 Translate the coordinates,
 Rotate the translated coordinates, and then
 Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra
dummy coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point P(X, Y) can be
converted to homogenous coordinates by P’ (Xh, Yh, h).
Translation
A translation moves an object to a different position on the screen. You can translate a point
in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new
coordinate (X’, Y’).

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 31


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

From the above figure, you can write that −


X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also
be represented using the column vectors.
$P = \frac{[X]}{[Y]}$ p' = $\frac{[X']}{[Y']}$T = $\frac{[t_{x}]}{[t_{y}]}$
We can write it as −
P’ = P + T
Rotation
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the
following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal
X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you
will get a new point P’ (X’, Y’).

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 32


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

Using standard trigonometric the original coordinate of point P(X, Y) can be represented as

$X = r \, cos \, \phi ...... (1)$
$Y = r \, sin \, \phi ...... (2)$
Same way we can represent the point P’ (X’, Y’) as −
${x}'= r \: cos \: \left ( \phi \: + \: \theta \right ) = r\: cos \: \phi \: cos \: \theta \: − \: r \: sin \:
\phi \: sin \: \theta ....... (3)$
${y}'= r \: sin \: \left ( \phi \: + \: \theta \right ) = r\: cos \: \phi \: sin \: \theta \: + \: r \: sin \:
\phi \: cos \: \theta ....... (4)$
Substituting equation (1) & (2) in (3) & (4) respectively, we will get
${x}'= x \: cos \: \theta − \: y \: sin \: \theta $
${y}'= x \: sin \: \theta + \: y \: cos \: \theta $
Representing the above equation in matrix form,
$$[X' Y'] = [X Y] \begin{bmatrix} cos\theta & sin\theta \\ −sin\theta & cos\theta
\end{bmatrix}OR $$
P’ = P . R
Where R is the rotation matrix
$$R = \begin{bmatrix} cos\theta & sin\theta \\ −sin\theta & cos\theta \end{bmatrix}$$
The rotation angle can be positive and negative.

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 33


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

For positive rotation angle, we can use the above rotation matrix. However, for negative
angle rotation, the matrix will change as shown below −
$$R = \begin{bmatrix} cos(−\theta) & sin(−\theta) \\ -sin(−\theta) & cos(−\theta)
\end{bmatrix}$$
$$=\begin{bmatrix} cos\theta & −sin\theta \\ sin\theta & cos\theta \end{bmatrix} \left
(\because cos(−\theta ) = cos \theta \; and\; sin(−\theta ) = −sin \theta \right )$$
Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.
Let us assume that the original coordinates are (X, Y), the scaling factors are (S X, SY), and
the produced coordinates are (X’, Y’). This can be mathematically represented as shown
below −
X' = X . SX and Y' = Y . SY
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below −
$$\binom{X'}{Y'} = \binom{X}{Y} \begin{bmatrix} S_{x} & 0\\ 0 & S_{y}
\end{bmatrix}$$
OR
P’ = P . S
Where S is the scaling matrix. The scaling process is shown in the following figure.

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 34


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

If we provide values less than 1 to the scaling factor S, then we can reduce the size of the
object. If we provide values greater than 1, then we can increase the size of the object.
Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a
rotation operation with 180°. In reflection transformation, the size of the object does not
change.
The following figures show reflections with respect to X and Y axes, and about the origin
respectively.

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 35


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

Shear
A transformation that slants the shape of an object is called the shear transformation. There
are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and
other shifts Y coordinate values. However; in both the cases only one coordinate changes its
coordinates and other preserves its values. Shearing is also termed as Skewing.
X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates, which
causes the vertical lines to tilt right or left as shown in below figure.

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 36


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

The transformation matrix for X-Shear can be represented as −


$$X_{sh} = \begin{bmatrix} 1& shx& 0\\ 0& 1& 0\\ 0& 0& 1 \end{bmatrix}$$
Y' = Y + Shy . X
X’ = X
Y-Shear
The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the
horizontal lines to transform into lines which slopes up or down as shown in the following
figure.

The Y-Shear can be represented in matrix from as −


$$Y_{sh} \begin{bmatrix} 1& 0& 0\\ shy& 1& 0\\ 0& 0& 1 \end{bmatrix}$$
X’ = X + Shx . Y
Y’ = Y

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 37


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

Lecture 14
homogeneous coordinates, composite transformations

Homogeneous Coordinates
The rotation of a point, straight line or an entire image on the screen, about a point other than
origin, is achieved by first moving the image until the point of rotation occupies the origin,
then performing rotation, then finally moving the image to its original position.
The moving of an image from one place to another in a straight line is called a translation. A
translation may be done by adding or subtracting to each point, the amount, by which picture
is required to be shifted.
Translation of point by the change of coordinate cannot be combined with other
transformation by using simple matrix application. Such a combination is essential if we wish
to rotate an image about a point other than origin by translation, rotation again translation.
To combine these three transformations into a single transformation, homogeneous
coordinates are used. In homogeneous coordinate system, two-dimensional coordinate
positions (x, y) are represented by triple-coordinates.
Homogeneous coordinates are generally used in design and construction applications. Here
we perform translations, rotations, scaling to fit the picture into proper position.
Example of representing coordinates into a homogeneous coordinate system: For two-
dimensional geometric transformation, we can choose homogeneous parameter h to any non-
zero value. For our convenience take it as one. Each two-dimensional position is then
represented with homogeneous coordinates (x, y, 1).
Following are matrix for two-dimensional transformation in homogeneous coordinate:

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 38


Unit 3 B.Tech. – V Semester Computer Graphics and Multimedia

Composite Transformation
If a transformation of the plane T1 is followed by a second plane transformation T2, then the
result itself may be represented by a single transformation T which is the composition of T1
and T2 taken in that order. This is written as T = T1∙T2.
Composite transformation can be achieved by concatenation of transformation matrices to
obtain a combined transformation matrix.
A combined matrix −
[T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]

Notes By :- Arvind Sharma(Head, Department of Computer Science and Engineering) Page 39


Where [Ti] is any combination of
 Translation
 Scaling
 Shearing
 Rotation
 Reflection
The change in the order of transformation would lead to different results, as in general
matrix multiplication is not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of
multiplication. The basic purpose of composing transformations is to gain efficiency by
applying a single composed transformation to a point, rather than applying a series of
transformation, one after another.
For example, to rotate an object about an arbitrary point (Xp, Yp), we have to carry out three
steps −
 Translate point (Xp, Yp) to the origin.
 Rotate it about the origin.
 Finally, translate the center of rotation back where it belonged.

4040 | P a g
e
Lecture 15
viewing pipeline and coordinates system

Viewing Pipeline

Window – world coordinate area for display


Viewport – area on display device to which window is mapped

Window – what is viewed


Viewport – where it is displayed

Viewing Transformations – mapping part of a world coordinate scene to device coordinates


aka – Window-Viewport Mapping

2D Viewing-Transformation Pipeline

4141 | P a g
e
Viewing Coordinate Reference Frame
Procedure:
1. Set up viewing-coordinate origin at some world position Po(xo,yo)
2. Set up orientation of reference frame
e.g. could set up view-up vector
can compute component of u = (ux, uy) & v = (vx,vy)
3. obtain matrix for converting world coordinates to viewing coordinates
i. translate viewing origin to world origin
ii. rotate to align two coordiate reference frame

Window-to-Viewport Coordinate Transformation


 Device transformations using:
o Xwl, Xwh, Ywl, Ywh
o Xvl, Xvh, Yvl, Yvh

 Use Transformation:
1. Set up windowvl
2. Translate window
3. Scale to normalize
4. Scale to viewport
5. Translate to Viewport

4242 | P a g
e
What are the final formulas?

Xv = [(Xvh - Xvl)/(Xwh - Xwl)] (X - Xwl) + Xvl

Yv = [(Yvh - Yvl) / (Ywh - Ywl)] (Yw - Ywl) + Yvl

Window-Viewport Mapping

Xwh Xwl Ywh Ywl Xwh-Xwl Ywh-Ywl


7.5 2.5 9 2.5 5 6.5

Xvh Xvl Yvh Yvl Xvh-Xvl Yvh-Yvl


900 400 700 400 500 300

No. x y X-Viewport Y-Viewport


1 1.0 4.0 250.000 469.231
2 4.0 10.0 550.000 746.154
3 8.0 8.0 950.000 653.846
4 8.0 4.0 950.000 469.231
1 1.0 4.0 250.000 469.231

Window Coordinates Viewport Coordinates


x y x y
2.5 2.5 400 400 Window/Viewport
2.5 9 400 700Outline
7.5 9 900 700
7.5 2.5 900 400
2.5 2.5 400 400

1.0 4.0 250 469 Data Points


4.0 10.0 550 746
8.0 8.0 950 654
8.0 4.0 950 469

4343 | P a g
e
1.0 4.0 250 469

44 | P a g e
Lecture 16
window-to-viewport transformation, Clipping including point clipping

Window to Viewport Transformation in Computer Graphics with Implementation


Window to Viewport Transformation is the process of transforming a 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.

General Terms:

 World coordinate – It is the Cartesian coordinate w.r.t which we define the diagram,
like Xwmin, Xwmax, Ywmin, Ywmax
 Device Coordinate –It is the screen coordinate where the objects is to be displayed,
like Xvmin, Xvmax, Yvmin, Yvmax
 Window –It is the area on world coordinate selected for display.
 ViewPort –It is the area on device coordinate where graphics is to be displayed.
Mathematical Calculation of Window to Viewport:

4545 | P a g
e
It may be possible that the size of the Viewport is much smaller or greater than the Window.
In these cases, we have to increase or decrease the size of the Window according to the
Viewport and for this, we need some mathematical calculations.
(xw, yw): A point on Window
(xv, yv): Corresponding point on Viewport
 we have to calcuate the point (xv, yv)

 Now the relative position of the object in Window and Viewport are same.
 For x coordinate,

For y coordinate,

 so, after calculating for x and y coordinate, we get

4646 | P a g
e
 where, sx is scaling factor of x coordinate and sy is scaling factor of y coordinate

Example:
Lets assume,
 for window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
 for viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
 Now a point ( Xw, Yw ) be ( 30, 80 ) on the window. We have to calculate that point on
viewport
i.e ( Xv, Yv ).
 First of all, calculate scaling factor of x coordinate Sx and scaling factor of y coordinate
Sy using above mentioned formula.
 Sx = ( 60 - 30 ) / ( 80 - 20 ) = 30 / 60
Sy = ( 60 - 40 ) / ( 80 - 40 ) = 20 / 40
 So, now calculate the point on viewport ( Xv, Yv ).
 Xv = 30 + ( 30 - 20 ) * ( 30 / 60 ) = 35
Yv = 40 + ( 80 - 40 ) * ( 20 / 40 ) = 60
 So, the point on window ( Xw, Yw ) = ( 30, 80 ) will be ( Xv, Yv ) = ( 35, 60 ) on
viewport.

4747 | P a g
e
Lecture 17
cohen-sutherland line clipping

Inside-Outside Window Codes


To determine whether endpoints are inside or outside a window, the algorithm sets up a half-
space code for each endpoint. Each edge of the window defines an infinite line that divides
the whole space into two half-spaces, the inside half-space and the outside half-space, as
shown below.

As you proceed around the window, extending each edge and defining an inside half-space
and an outside half-space, nine regions are created - the eight "outside" regions and the one
"inside"region. Each of the nine regions associated with the window is assigned a 4-bit code
to identify the region. Each bit in the code is set to either a 1(true) or a 0(false). If the region
is to the left of the window, the first bit of the code is set to 1. If the region is to the top of
the window, the second bit of the code is set to 1. If to the right, the third bit is set, and if to
the bottom, the fourth bit is set. The 4 bits in the code then identify each of the nine regions
as shown below.

4848 | P a g
e
For any endpoint ( x , y ) of a line, the code can be determined that identifies which region
the endpoint lies. The code's bits are set according to the following conditions:

The sequence for reading the codes' bits is LRBT (Left, Right, Bottom, Top).
Once the codes for each endpoint of a line are determined, the logical AND operation of the
codes determines if the line is completely outside of the window. If the logical AND of the
endpoint codes is not zero, the line can be trivally rejected. For example, if an endpoint had a
code of 1001 while the other endpoint had a code of 1010, the logical AND would be 1000
which indicates the line segment lies outside of the window. On the other hand, if the
endpoints had codes of 1001 and 0110, the logical AND would be 0000, and the line could
not be trivally rejected.
The logical OR of the endpoint codes determines if the line is completely inside the window.
If the logical OR is zero, the line can be trivally accepted. For example, if the endpoint codes
are 0000 and 0000, the logical OR is 0000 - the line can be trivally accepted. If the endpoint
codes are 0000 and 0110, the logical OR is 0110 and the line can not be trivally accepted.
Algorithm
The Cohen-Sutherland algorithm uses a divide-and-conquer strategy. The line segment's
endpoints are tested to see if the line can be trivally accepted or rejected. If the line cannot be
trivally accepted or rejected, an intersection of the line with a window edge is determined and
the trivial reject/accept test is repeated. This process is continued until the line is accepted.
To perform the trivial acceptance and rejection tests, we extend the edges of the window to
divide the plane of the window into the nine regions. Each end point of the line segment is
then assigned the code of the region in which it lies.
1. Given a line segment with endpoint and
2. Compute the 4-bit codes for each endpoint.
If both codes are 0000,(bitwise OR of the codes yields 0000 ) line lies
completely inside the window: pass the endpoints to the draw routine.
If both codes have a 1 in the same bit position (bitwise AND of the codes
is not 0000), the line lies outside the window. It can be trivially rejected.

4949 | P a g
e
3. If a line cannot be trivially accepted or rejected, at least one of the two endpoints must
lie outside the window and the line segment crosses a window edge. This line must
be clipped at the window edge before being passed to the drawing routine.
4. Examine one of the endpoints, say . Read 's 4-bit code in
order: Left-to-Right, Bottom-to-Top.
5. When a set bit (1) is found, compute the intersection I of the corresponding window
edge with the line from to . Replace with I and repeat the algorithm.

50
|Page
Lecture 18
liang- bersky line clipping

The Liang-Barsky algorithm is a line clipping algorithm. This algorithm is more efficient
than Cohen–Sutherland line clipping algorithm and can be extended to 3-Dimensional
clipping. 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 intersections between the line and the clip window.
The parametric equation of a line can be given by,
X = x1 + t(x2-x1)
Y = y1 + t(y2-y1)
Where, t is between 0 and 1.
Then, writing the point-clipping conditions in the parametric form:
xwmin <= x1 + t(x2-x1) <= xwmax
ywmin <= y1 + t(y2-y1) <= ywmax
The above 4 inequalities can be expressed as,
tpk <= qk
Where k = 1, 2, 3, 4 (correspond to the left, right, bottom, and top boundaries, respectively).
The p and q are defined as,
p1 = -(x2-x1), q1 = x1 - xwmin (Left Boundary)
p2 = (x2-x1), q2 = xwmax - x1 (Right Boundary)
p3 = -(y2-y1), q3 = y1 - ywmin (Bottom Boundary)
p4 = (y2-y1), q4 = ywmax - y1 (Top Boundary)
When the line is parallel to a view window boundary, the p value for that boundary is zero.
When pk < 0, as t increase line goes from the outside to inside (entering).
When pk > 0, line goes from inside to outside (exiting).
When pk = 0 and qk < 0 then line is trivially invisible because it is outside view window.
When pk = 0 and qk > 0 then the line is inside the corresponding window boundary.
Using the following conditions, the position of line can be determined:

CONDITION POSITION OF LINE

51
|Page
CONDITION POSITION OF LINE

parallel to the clipping


pk = 0
boundaries

pk = 0 and qk < 0 completely outside the boundary


pk = 0 and qk >= inside the parallel clipping
0 boundary
line proceeds from outside to
pk < 0 inside
line proceeds from inside to
pk > 0 outside

Parameters t1 and t2 can be calculated that define the part of line that lies within the clip
rectangle.
When,
1. pk < 0, maximum(0, qk/pk) is taken.
2. pk > 0, minimum(1, qk/pk) is taken.
If t1 > t2, the line is completely outside the clip window and it can be rejected. Otherwise, the
endpoints of the clipped line are calculated from the two values of parameter t.
Algorithm –
1. Set tmin=0, tmax=1.
2. Calculate the values of t (t(left), t(right), t(top), t(bottom)),
(i) If t < tmin ignore that and move to the next edge.
(ii) else separate the t values as entering or exiting values using the inner product.
(iii) If t is entering value, set tmin = t; if t is existing value, set tmax = t.
3. If tmin < tmax, draw a line from (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) to (x1 + tmax(x2-x1), y1 +
tmax(y2-y1))
4. If the line crosses over the window, (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) and (x1 + tmax(x2-
x1), y1 + tmax(y2-y1)) are the intersection point of line and edge.
This algorithm is presented in the following code. Line intersection parameters are initialised
to the values t1 = 0 and t2 = 1.

52
|Page
Lecture 19
NLN line clipping, polygon clipping
One of the problems common to both the Cohen-Sutherland and the Liang-Barsky algorithm is that more
intersections are computed than necessary. For example, consider Figure 3.6 again where we are clipping line
segment [P1,P2] against the window. The Cohen-Sutherland algorithm will compute the intersection of the
segment with the top boundary at t4 even though the segment is later rejected. The Liang-Barsky algorithm will
actually compute all the parameter values corresponding to the intersection of the line with the window.
Avoiding many of these wasted computations is what the Nicholl-Lee-Nicholl line-clipping algorithm
([NiLN87]) is all about. These authors also make a detailed analysis of the deficiencies of the Cohen-Sutherland
and Liang-Barsky algorithms. Their final algorithm is much faster than either of these. It is not really much
more complicated conceptually, but involves many cases. We describe one basic case below.
Assume that we want to clip a segment [P1,P2] against a window. The determination of the exact edges, if
any, that one needs to intersect, reduces, using symmetry, to an analysis of the three possible positions of P1
shown in Figure 3.8. The cases are
(1) P1 is in the window (Figure 3.8(a)),
(2) P1is in a “corner region” (Figure 3.8(b)), or
(3) P1 is in an “edge region” (Figure 3.8(c)).
For each of these cases one determines the regions with the property that no matter where in the region the
second point P2 is, the segment will have to be intersected with the same boundaries of the window. These
regions are also indicated in Figure 3.8. As one can see, these regions are determined by drawing the rays from
P1 through the four corners of the window. The following abbreviations were used:

T – ray intersects top boundary LT – ray intersects left and top boundary

L – ray intersects left boundary LR – ray intersects left and right boundary

B – ray intersects bottom boundary LB – ray intersects left and bottom boundary

R – ray intersects right boundary TR – ray intersects top and right boundary

TB – ray intersects top and bottom boundary

Sutherland-Hodgman Polygon Clipping

One of the earliest polygon-clipping algorithms is the Sutherland-Hodgman algorithm ([SutH74]). It is based
on clipping the entire subject polygon against an edge of the window (more precisely, the halfplane determined
by that edge which contains the clip polygon), then clipping the new polygon against the next edge of the

53
|Page
window, and so on, until the polygon has been clipped against all of the four edges. An important aspect of their
algorithm is that one can avoid generating a lot of intermediate data.
Representing a polygon as a sequence of vertices P1, P2, . . ., Pn, suppose that we want to clip against a
single edge e. The algorithm considers the input vertices Pi one at a time and generates a new sequence Q1, Q2,
. . ., Qm. Each Pi generates 0, 1, or 2 of the Qj, depending on the position of the input vertices with respect to e. If
we consider each input vertex P, except the first, to be the terminal vertex of an edge, namely the edge defined by
P and the immediately preceding input vertex, call it S, then the Q’s generated by P depend on the
relationship between the edge [S,P] and the line L determined by e. There are four possible cases. See Figure
3.9. The window side of the line is marked as “inside.” The circled vertices are those that are output. Figure 3.10
shows an example of how the clipping works. Clipping the polygon with vertices labeled Pi against edge e1
produces the polygon with vertices Qi. Clipping the new polygon against edge e2 produces the polygon with
vertices Ri.
Note that we may end up with some bogus edges. For example, the edge R5R6 in Figure 3.10 is not a part of
the mathematical intersection of the subject polygon with the clip polygon.

Figure 3.9. The four cases in Sutherland- Hodgman polygon clipping.

Figure 3.10. A Sutherland-Hodgman polygon-clipping example.


Eliminating such edges from the final result would be a nontrivial effort, but normally they do not cause any
problems. We run into this bogus edge problem with other clipping algorithms also.

54
|Page

You might also like