0% found this document useful (0 votes)
23 views89 pages

CG Lecture2&3

The document discusses 2D geometric transformations including translation, rotation, scaling and shearing. It explains how these basic transformations can be represented using matrix mathematics and combined to perform more complex transformations. Homogeneous coordinates are also introduced as a convenient way to represent points for transformations.

Uploaded by

abebaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views89 pages

CG Lecture2&3

The document discusses 2D geometric transformations including translation, rotation, scaling and shearing. It explains how these basic transformations can be represented using matrix mathematics and combined to perform more complex transformations. Homogeneous coordinates are also introduced as a convenient way to represent points for transformations.

Uploaded by

abebaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 89

2D Geometric Transformations

1
Contents
• Definition & Motivation
• Basic 2D Geometric Transformation
– Translation
– Rotation
– Scaling
• Matrix Representation
• Homogeneous Coordinates
• Matrix Composition
• Composite Transformations
– Pivot-Point Rotation
– General Fixed-Point Scaling
– Reflection and Shearing
– Transformations Between Coordinate Systems

2
Geometric Transformation

• Definition
– Translation, Rotation, Scaling

• Motivation – Why do we need geometric


transformations in CG?
– As a viewing aid
– As a modeling tool
– As an image manipulation tool

3
Example: 2D Geometric Transformation
Modeling
Coordinates

World Coordinates

4
Example: 2D Scaling
Modeling
Coordinates

Scale(0.3, 0.3)

World Coordinates

5
Example: 2D Rotation
Modeling
Coordinates

Scale(0.3, 0.3)
Rotate(-90)

World Coordinates

6
Example: 2D Translation
Modeling
Coordinates

Scale(0.3, 0.3)
Rotate(-90)
Translate(5, 3)

World Coordinates

7
Example: 2D Geometric Transformation
Modeling
Coordinates

Again?

World Coordinates

8
Example: 2D Geometric Transformation
Modeling
Coordinates
Scale
Translate

Scale
Rotate
Translate

World Coordinates

9
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ

y  y  sinθ  y  cosθ

• Shear
x   x  hx  y
– y  y  hy  x

10
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ Transformations
– can be combined
y  y  sinθ  y  cosθ (with simple algebra)

• Shear
x   x  hx  y
– y  y  hy  x

11
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ

y  y  sinθ  y  cosθ

• Shear x   x  sx
x   x  hx  y
– y  y  hy  x y  y  sy

12
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ

y  y  sinθ  y  cosθ

• Shear x   ((x  sx)  cos  (y  sy)  sin  )
x   x  hx  y
– y  y  hy  x y  ((x  sx)  sin   (y  sy)  cos )

13
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ

y  y  sinθ  y  cosθ

• Shear x   ((x  sx)  cos  (y  sy)  sin  )  tx
x   x  hx  y
– y  y  hy  x y  ((x  sx)  sin   (y  sy)  cos )  ty

14
Basic 2D Transformations
• Translation

x   x  tx

– y  y  ty
• Scale

x  x  sx
– y  y  sy
• Rotation
x   x  cosθ - y  sinθ

y  y  sinθ  y  cosθ

• Shear x   ((x  sx)  cos  (y  sy)  sin  )  tx
x   x  hx  y
– y  y  hy  x y  ((x  sx)  sin   (y  sy)  cos )  ty

15
Matrix Representation
• Represent a 2D Transformation by a Matrix
a b 
c d 
 

• Apply the Transformation to a Point


x  ax  by  x   a b   x 
 y    c d   y 
y  cx  dy     
Transformation
Matrix Point
16
Matrix Representation
• Transformations can be combined by matrix
multiplication
 x    a b  e f  i j   x 
 y    c d   g    
h k l   y 
   
Transformation
Matrix

Matrices are a convenient and efficient way


to represent a sequence of transformations

17
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Identity
x  x  x  1 0  x 
 y  0 1  y 
y  y     
2D Scaling

x  sx  x  x   sx 0   x 
y  sy  y  y  0 sy   y 
    

18
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Rotation
x  cos   x  sin   y  x  cos   sin    x 
 y  sin  cos    y 
y  sin   x  cos   y     
2D Shearing
x  x  shx  y  x  1 shx   x 
y  shy  x  y  y   shy 1  y 
    

19
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Mirror over Y axis
x   x  x    1 0   x 
y  y  y    0 1   y 
    
2D Mirror over (0,0)
x   x  x    1 0   x 
y   y  y  0  1  y 
    

20
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Translation
x  x  tx
NO!!
y  y  ty

21
2D Translation
• 2D translation can be represented by a 3×3
matrix
– Point represented with homogeneous coordinates
 x  1 0 tx   x 
x   x  tx  y  0 1 ty   y 
y  y  ty     
1  0 0 1  1 

22
Basic 2D Transformations
• Basic 2D transformations as 3x3 Matrices
 x  1 0 tx   x   x   sx 0 0   x 
 y  0 1 ty   y   y  0 sy 0  y 
         
1  0 0 1  1  1  0 0 1  1 
Translate Scale

 x  cos   sin  0   x   x  1 shx 0   x 


 y  sin  cos  0  y  y   shy 1 0  y 
         
1  0 0 1  1  1  0 0 1 1 

Rotate Shear

23
Homogeneous Coordinates
• Add a 3rd coordinate to every 2D point
– (x, y, w) represents a point at location (x/w, y/w)
– (x, y, 0) represents a point at infinity
– (0, 0, 0) Is not allowed
y
2 (2, 1, 1) or (4, 2, 2) or (6, 3, 3)
1
x
1 2

Convenient Coordinate System to


Represent Many Useful Transformations

24
Matrix Composition
• Transformations can be combined by matrix
multiplication
 x   1 0 tx  cos θ - sinθ 0  sx 0 0   x 
 y    0 1 ty   sinθ cosθ 0 0 sy 0    y 
       
 w  0 0 1   0 0 1  0 0 1    w 
p  T(tx, ty) R( ) S(sx, sy) p

• Matrix multiplication is associative

p  (T  (R  (S  p))) p  (T  R  S)  p
25
Matrix Composition
• Rotate by  around arbitrary point (a,b)
– M  T(a, b)  R(θ )  T(-a,-b)

(a,b)

• Scale by sx, sy around arbitrary point (a,b)


– M  T(a, b)  S(sx, sy)  T(-a,-b)

(a,b)

26
Pivot-Point Rotation

(xr,yr) (xr,yr) (xr,yr) (xr,yr)

Translate Rotate Translate

T xr , yr  R  T  xr , yr   Rxr , yr , 


1 0 x r  cos   sin  0 1 0  x r  cos   sin  x r (1  cos  )  y r sin  
0 1 y    sin  cos  0  0 1  y    sin  cos  y (1  cos  )  x sin  
 r    r  r r 
0 0 1   0 0 1 0 0 1   0 0 1 

27
General Fixed-Point Scaling

(xf,yf) (xf,yf) (xf,yf) (xf,yf)

Translate Scale Translate

T x f , y f  S s x , s y  T  x f , y f   S x f , y f , s x , s y 
1 0 xf  s x 0 0  1 0  xf  s x 0 x f (1  s x ) 
0 1 yf 0 sy 0  0 1  yf 0 sy y f (1  s y )
    
0 0 1   0 0 1 0 0 1   0 0 1 

28
Reflection
• Reflection with respect to the axis
• x-axis • y-axis • Origin
1 0 0    1 0 0   1 0 0
0  1 0   0 1 0  0  1 0
     
0 0 1  0 0 1  0 0 1

y 1 y y
1 1’ 1’

2 3 2 3 3’ 2 3’ 2
x x 3 x
2’ 3’ 1

1’ 2

29
Reflection
 Reflection with respect to a Line

y
0 1 0 
1 0 0 
  x
0 0 1
y=x
 Clockwise rotation of 45  Reflection about the x axis 
Counterclockwise rotation of 45 

y y 1
y
2 3
x x
2’ 3’ x

1’

30
OpenGL Geometric-Transformation
Functions

• In the core OpenGL library,


– a separate function is available for each basic
transformation (translate, rotate, scale)
– all transformations are specified in 3D
• Parameters
– Translation: translation amount in x, y, z axes
– Rotation: angle, orientation of the rotation axis
that passes through the origin
– Scaling: scaling factors for three coordinates
Basic OpenGL Transformations
• glTranslate* (tx, ty, tz);
– For 2D applications set tz = 0
• glRotate* (theta, vx, vy, vz);
– theta in degrees
– The rotation axis is defined by the vector (vx,vy,vz)
• glScale* (sx, sy, sz);
– Scaling factors for the three coordinates
OpenGL Matrix Operations
• OpenGL maintains three sets of matrices for
performing various transformation operations
– Modelview matrix: used for transforming objects
in the scene and for changing the coordinates
– Projection matrix: handles parallel and
perspective projections
– Texture matrix: this is used in specifying how
textures are mapped onto objects
OpenGL Matrix Operations
• OpenGL uses the ff. command to set the
current matrix mode
glMatrixMode(mode);
– Where mode is GL_MODELVIEW, GL_PROJECTION, or GL_ TEXTURE
• To set the matrix mode to modelview :
– glMatrixMode(GL_MODELVIEW);
OpenGL Matrix Operations

• Once you are in the modelview mode, a call to a


transformation routine generates a matrix that
is multiplied by the current matrix for that mode
• Whatever object defined is multiplied with the
current matrix
• The contents of the current matrix can also be
manipulated explicitly
Example1-a rectangle in OpenGL
#include <gl/gl.h>
#include <GL/glut.h>
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowSize( 500,500 );
glutInitWindowPosition(0,0 );
glutCreateWindow( “rectangle” );
init();
glutDisplayFunc( display );
glutMainLoop();
return 0;
}
Example1-a rectangle in OpenGL
void init(void) // Specify 2D WCS
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,100,0,100);
}
Example1-a rectangle in OpenGL
void rec1()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(50.0,0.0);
glVertex2f(50.0,50.0);
glVertex2f(0.0,50.0);
glEnd();
glFlush();
}
Example1-a rectangle in OpenGL
Example2-a rectangle centered at (50,50) in
WCS
void rec2()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(25.0,25.0);
glVertex2f(75.0,25.0);
glVertex2f(75.0,75.0);
glVertex2f(25.0,75.0);
glEnd();
glFlush();
}
Example2-a rectangle centered at (50,50) in
WCS
Example3- Rotate the rectangle in
example2 by 200 CCW about (0,0)
void display()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(20, 0.0,0.0, 1.0);


Rec2();

glFlush();
}
Example3- Rotate the rectangle in
example2 by 200 CCW about (0,0)
Example4- Rotate the rectangle in example2
by 200 CCW about (50,50)
void display()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(50.0,50.0,0);
glRotatef(20, 0.0,0.0, 1.0);
glTranslatef(-50.0,-50.0,0);
Rect2();

glFlush();
}
Example4- Rotate the rectangle in example2
by 200 CCW about (50,50)
3 DIMENSIONAL
TRANSFORMATIONS
3D Transformations
• Analogous to 2D we have 4 dimensions in homogenous
coordinates.
• Basic transformations:
– Translation Y

– Rotation
– Scaling X

Z
Translation
• move the object to a relative position.
y
 x  1 0 0 tx   x P
 y   0 1 0 t y   y 
   x
P
 z   0 0 1 tz   z  z
     
 1  0 0 0 1  1  y

P  T  P
x

z
Rotation
• Rotation around the coordinate axes
y y y

x x x

z z z

x axis y axis z axis


Rotation around coordinate axes
1 0 0 0
• Around x 0 cos   sin  0
R x ( )   P  R x ( )  P
0 sin  cos  0
 
0 0 0 1

 cos  0 sin  0
• Around y  0 1 0 0
R y ( )   P  R y ( )  P
 sin  0 cos  0
 
 0 0 0 1

cos   sin  0 0
 sin  cos  0 0
• Around z R z ( )   P  R z ( )  P
 0 0 1 0
 
 0 0 0 1
Rotation Around a Parallel Axis
• Rotating the object around a line parallel to one of the axes:
Translate to axis, rotate, translate back.
P  T(0, y p , z p )  R x ( )  T(0, y p , z p )  P

y y y y

x
x
x x
z z z
z

Translate Rotate Translate back


Scaling
• Change the coordinates of the object by scaling factors.
y
P
sx 0 0 0
x' x P
y' 0 sy 0 0 y x
z' 0 0 sz 0 z
1 0 0 0 1 1 z
y
'
P S P

P  S  P
x

z
Scaling with respect to a Fixed Point
• Translate to origin, scale, translate back
P   T( x f , y f , z f )  S  T(  x f ,  y f ,  z f )  P
y y x
y y

x
x x
z z z
z

Translate Scale Translate back


OpenGL Matrix Stacks
• OpenGL maintains a matrix stack for all matrix
modes
• When we apply geometric transformations
using OpenGL functions, the 4 by 4 matrix at
the top of the matrix stack is modified
• The top is also called the current matrix
OpenGL Matrix Stacks
• OpenGL has the following basic stack operations
– glLoadIdentity(): Sets the current matrix to the identity
matrix
– glLoadMatrix*(M): Loads a given matrix over the
current matrix
– glMultMatrix*(M): Multiplies the current matrix by a
given matrix and replaces the current matrix with this
result.
– glPushMatrix(): Pushes a copy of the current matrix on
top the stack
– glPopMatrix(): Pops the current matrix off the stack
Example: Draw a rotated triangle
glBegin(GL_TRIANGLES)
– glPushMatrix(); // save the current matrix
– glRotatef(45, 0, 0, 1); // rotate by 45 degrees CCW
– glVertex2i(2, 2); //first vertex
– glVertex2i(50, 2); // second vertex
– glVertex2i(50, 50); //third vertex
– glPopMatrix(); // restore the old matrix
glEnd();
2D Viewing
Introduction
• Given output primitives are specified in world
coordinates
• Graphics APIs must be told how to map world
coordinates onto screen/viewing coordinates
• Could be done in two ways
– Provide a transformation function that maps WC to
SC(VC)
– Specify a rectangular region in WCs called WC
window/Clipping window and a corresponding
rectangular region in SCs called Viewport
2D Viewing
• World coordinates to Viewing coordinates
– Window to Viewport
• Window: A region of the scene selected for viewing (also
called clipping window)
• Viewport: A region on display device for mapping to window
Viewport

Window

World Coordinates Viewing Coordinates


Clipping Window Vs. Viewport
• The clipping window selects what we want to see in
our virtual 2D world
• The viewport indicates where it is to be viewed on
the output device (or within the display window)
• By default the viewport have the same location and
dimensions of the GLUT display window you create
– But it can be modified so that only a part of the
display window is used for OpenGL display
Window to Viewport
• Given a window and viewport, what is the
transformation matrix that maps the window
from world coordinate into the viewport in
screen coordinates
• This matrix can be developed as a three step
transformation composition
– Window is translated to the origin of WC
– Size of the window is scaled to be equal to size of the
viewport
– Translation is used to position the viewport
Window to Viewport
OpenGL 2D Viewing Functions

• OpenGL, GLU, and


GLUT provide
functions to specify
clipping windows,
viewports, and
display windows
within a video
screen.
Setting up a 2D Clipping-Window

• glMatrixMode (GL_PROJECTION)
• glLoadIdentity ();
• gluOrtho2D (xwmin, xwmax, ywmin, ywmax);
or
• glOrtho (xwmin, xwmax, ywmin, ywmax, zwmin,
zwmax);
Setting up a Viewport
• glViewport (xvmin, yvmin, vpWidth, vpHeight);
• All the parameters are given in integer screen
coordinates relative to the lower-left corner of the
display window.
• If we do not invoke this function, by default, a
viewport with the same size and position of the
display window is used (i.e., all of the GLUT window
is used for OpenGL display)
Creating a GLUT Display Window
• glutInitWindowPosition (xTopLeft, yTopLeft);
– the integer parameters are relative to the top-left corner
of the screen
• glutInitWindowSize (Width, Height);
• glutCreateWindow (“Title of Display Window”);
• glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)
– Specification of the buffer that will be used
• glClearColor (red, green, blue, alpha)
– Specify the background color
OpenGL 2D Viewing Example
• 2 Viewports
• One triangle is displayed in
two colors and
orientations in 2 viewports
glutInitWindowSize (600, 300);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glViewport(0, 0, 300, 300);
drawCenteredTriangle();

glColor3f(1.0, 0.0, 0.0);


glViewport(300, 0, 300, 300);
glRotatef(90.0, 0.0, 0.0, 1.0);
drawCenteredTriangle();
2D Clipping
• Clipping: identifying the parts of the objects
that will be inside of the window.
• Everything outside the clipping window is
eliminated from the scene description (i.e.,
not scan converted) for efficiency.
– Point Clipping
– Line Clipping
– Polygon Clipping
Point Clipping
• A point (x,y) is not clipped if:
wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax
• otherwise it is clipped
P4 Clipped
Clipped

Window P2
wymax
Clipped
P5
P1
P7 Points Within the Window
are Not Clipped
P9 P8
wymin
Clipped P10

wxmin wxmax
Line Clipping
• Examine the end-points of each line to see if
they are in the window or not
Situation Solution Example

Both end-points inside


Don’t clip
the window

One end-point inside


the window, one Must clip
outside

Both end-points
Must clip
outside the window
Brute Force Line Clipping
• Brute force line clipping can be performed as
follows:
– Don’t clip lines with both
end-points within the
window
– For lines with one end-
point inside the window
and one end-point
outside, calculate the
intersection point (using the equation of the line)
and clip from this point out
Brute Force Line Clipping (cont…)
– For lines with both end-
points outside the window
test the line for
intersection with all of the
window boundaries, and
clip appropriately

However, calculating line intersections is


computationally expensive
Because a scene can contain so many lines, the brute
force approach to clipping is much too slow
Cohen-Sutherland Clipping
Algorithm
• An efficient line clipping algorithm
• The key advantage of the algorithm is that it
vastly reduces the number of line
intersections that must be calculated
Cohen-Sutherland: World Division
• World space is divided into regions based on
the window boundaries
– Each region has a unique four bit region code
– Region codes indicate the position of the regions
with respect to the window
1001 1000 1010
3 2 1 0
0000
above below right left 0001 0010
Window
Region Code Legend
0101 0100 0110
Cohen-Sutherland: Labelling
• Every end-point is labelled with the
appropriate region code
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Lines In The
Window
Lines completely contained within the window
boundaries have region code [0000] for both
end-points so are not clipped
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Lines Outside The
Window
Any lines with a common set bit in the region
codes of both end-points can be clipped
– The AND operation can efficiently check this
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Other Lines
• Lines that cannot be identified as completely
inside or outside the window may or may not
cross the window interior
• These lines are processed as follows:
– Compare an end-point outside the window to a
boundary (choose any order in which to consider
boundaries e.g. left, right, bottom, top) and
determine how much can be discarded
– If the remainder of the line is entirely inside or
outside the window, retain it or clip it respectively
Cohen-Sutherland: Other Lines (cont…)
– Otherwise, compare the remainder of the line against
the other window boundaries
– Continue until the line is either discarded or a segment
inside the window is found
• We can use the region codes to determine which
window boundaries should be considered for
intersection
– To check if a line crosses a particular boundary we
compare the appropriate bits in the region codes of its
end-points
– If one of these is a 1 and the other is a 0 then the line
crosses the boundary
Cohen-Sutherland Examples
• Consider the line P9 to P10 below
Window
– Start at P10 wymax
– From the region codes
of the two end-points we
know the line doesn’t P [0000]
9
wymin
cross the left or right P ’ [0000]
10

boundary P [0100]
10

– Calculate the wxmin wxmax


intersection of the line with the bottom boundary to generate
point P10’
– The line P9 to P10’ is completely inside the window so is
retained
Cohen-Sutherland Examples (cont…)
• Consider the line P3 to P4 below P4 [1000]
P4’ [1001]
– Start at P4 wymax
Window

– From the region codes P3 [0001]


of the two end-points
we know the line
crosses the left wymin
boundary so calculate
the intersection point to
generate P4’ wxmin wxmax

– The line P3 to P4’ is completely outside the window so is


clipped
Cohen-Sutherland Examples (cont…)
• Consider the line P7 to P8 below
– Start at P7 Window
wymax
– From the two region
codes of the two P7’ [0000]

end-points we know P7 [0001]


P8’ [0000]
P8 [0010]

the line crosses the wymin

left boundary so
calculate the wxmin wxmax
intersection point to
generate P7’
Cohen-Sutherland Examples (cont…)
• Consider the line P7’ to P8
– Start at P8 Window
wymax
– Calculate the
intersection with the P7’ [0000]
P7 [0001] P8 [0010]
right boundary to P8’ [0000]
wymin
generate P8’
– P7’ to P8’ is inside
wxmin wxmax
the window so is
retained
Calculating Line Intersections
• Intersection points with the window boundaries are
calculated using the line-equation parameters
– Consider a line with the end-points (x1, y1) and (x2, y2)
– The y-coordinate of an intersection with a vertical window
boundary can be calculated using:
y = y1 + m (xboundary - x1)

where xboundary can be set to either wxmin or wxmax


Calculating Line Intersections (cont…)
– The x-coordinate of an intersection with a
horizontal window boundary can be calculated
using:
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
– m is the slope of the line in question and can be
calculated as m = (y2 - y1) / (x2 - x1)
Area Clipping
• Similarly to lines, areas
must be clipped to a
window boundary
• Consideration must be
taken as to which
portions of the area must
be clipped
Sutherland-Hodgman Area
Clipping Algorithm
• A technique for clipping areas developed by
Sutherland & Hodgman
• Put simply the polygon is clipped by comparing it
against each boundary in turn

Original Area Clip Left Clip Right Clip Top Clip Bottom
Sutherland-Hodgman Area Clipping
Algorithm (cont…)
• To clip an area against an individual boundary:
– Consider each vertex in turn against the boundary
– Vertices inside the boundary are saved for clipping
against the next boundary
– Vertices outside the boundary are clipped
– If we proceed from a point inside the boundary to
one outside, the intersection of the line with the
boundary is saved
– If we cross from the outside to the inside,
intersection point and the vertex are saved
Sutherland-Hodgman Example
• Each example S
shows the point
being processed (P) P
I
S

and the previous P


point (S) Save Point P Save Point I

• Saved points define P S


area clipped to the I P

boundary in
question
S
No Points Saved Save Points I & P

You might also like