SlideShare a Scribd company logo
UNIT II
TWO-
DIMENSIONAL
GRAPHICS
CONTENT
Two dimensional geometric transformations — Matrix
representations and homogeneous coordinates, composite
transformations; Two dimensional viewing — viewing pipeline,
viewing coordinate reference frame; window-to-viewport
coordinate transformation, Two dimensional viewing functions;
clipping operations — point, line, and polygon clipping
algorithms.
Transformation
Transform every point on an object according to certain rule.
Initial Object
Transformed Object
P (x,y)
Q (x’, y’)
x x’
y y’
T
The point Q is the image of P under the
transformation T.
Translation
  
  
x x t
y y t
x
y
(10,5) (30,5)
(20,35)
(55,60)
(65,30)
(45,30)
The vector (tx, ty) is called the offset vector.
Translation (OpenGL)
Specifying a 2D-Translation:
glTranslatef(tx, ty, 0.0);
(The z component is set to 0 for 2D translation).
(x,y)
(x’,y’)
q
  
  
x x y
y x y
cos sin
sin cos
q q
q q
o
(x,y)
(x’,y’)
x
y
Rotation About the Origin
The above 2D rotation is actually a rotation about the
z-axis (0,0,1) by an angle q.
Rotation About the Origin
Specifying a 2D-Rotation about the origin:
glRotatef(theta, 0.0, 0.0, 1.0);
theta: Angle of rotation in degrees.
The above function defines a rotation about the z-axis (0,0,1).
(xp , yp)
(x,y)
(x’,y’)
Pivot Point
•Pivot point is the point of rotation
•Pivot point need not necessarily be on the object
Rotation About a Pivot Point
(xp , yp)
p
p
y
y
y
x
x
x




1
1
(x,y)
(x1, y1)
STEP-1: Translate the pivot point to the origin
Rotation About a Pivot Point
q
q
q
q
cos
1
sin
1
2
sin
1
cos
1
2
y
x
y
y
x
x




(x1, y1)
STEP-2: Rotate about the origin
(x2, y2)
Rotation About a Pivot Point
p
p
y
y
y
x
x
x






2
2
STEP-3: Translate the pivot point to original position
(x2, y2)
(xp, yp)
(x’, y’)
Rotation About a Pivot Point
     
     
x x x y y x
y x x y y y
p p p
p p p
( )cos ( )sin
( )sin ( )cos
q q
q q
Specifying a 2D-Rotation about a pivot point (xp,yp):
glTranslatef(xp, yp, 0);
glRotatef(theta, 0, 0, 1.0);
glTranslatef(-xp, -yp, 0);
Note the OpenGL specification of the sequence of transformations in the
reverse order !
Rotation About a Pivot Point
 
 
x x s
y y s
x
y
.
.
s s
x y

Uniform Non-Uniform
s s
x y

( , )
s s
x y  0
(x,y)
(x’,y’)
(x,y)
(x’,y’)
Scaling About the Origin
The parameters sx, sy are called scale factors.
Specifying a 2D-Scaling with respect to the origin:
glScalef(sx, sy, 1.0);
sx, sy: Scale factors along x, y.
For proper scaling sx, sy must be positive.
For 2D scaling, the third scale factor must be set to 1.0.
Scaling About the Origin
(xf , yf )
f
y
f
f
x
f
y
s
y
y
y
x
s
x
x
x








).
(
).
(
(x,y)
(x’,y’)
• Translate the fixed point to origin
• Scale with respect to the origin
•Translate the fixed point to its original
position.
Scaling About a Fixed Point
Reflections Initial
Object
Reflection about x
y =  y
x
y
Reflection about
origin
x =  x
y =  y
Reflection about y
x =  x
Reflections
Reflection about x: glScalef(1, -1, 1);
Reflection about y: glScalef(-1, 1, 1);
Reflection about origin: glScalef(-1, -1, 1);
Shear
  
 
x x h y
y y
x
•A shear transformation in the x-direction (along x)
shifts the points in the x-direction proportional
to the y-coordinate.
•The y-coordinate of each point is unaffected.







 





 













 




















 












x
y
x
y
t
t
x
y
x
y
x
y
s
s
x
y
x
y
x
y
cos sin
sin cos
q q
q q
0
0
Translation
Rotation [Origin]
Scaling [Origin]
Matrix Representations


































































y
x
y
x
y
x
y
x
y
x
y
x
1
0
0
1
1
0
0
1
1
0
0
1
Reflection about x
Matrix Representations
Reflection about y
Reflection about
the Origin










































y
x
h
y
x
y
x
h
y
x
1
0
1
1
0
1
Shear along x
Matrix Representations
Shear along y
Homogeneous Coordinates
To obtain square matrices an additional row was added to the matrix and an
additional coordinate, the w-coordinate, was added to the vector for a point. In
this way a point in 2D space is expressed in three-dimensional homogeneous
coordinates.
This technique of representing a point in a space whose dimension is one
greater than that of the point is called homogeneous representation. It
provides a consistent, uniform way of handling affine transformations.
Cartesian Homogeneous
0
),
,
,
(
,
0
),
,
,
(
)
,
(












c
c
b
a
c
b
c
a
h
h
yh
xh
y
x
Examples: (5, 8) (15, 24, 3)
(x, y) (x, y, 1)
Homogeneous Coordinates
•If we use homogeneous coordinates, the geometric
transformations given above can be represented using
only a matrix pre-multiplication.
• A composite transformation can then be represented
by a product of the corresponding matrices.




































































































x
y
t
t
x
y
x
y
x
y
x
y
s
s
x
y
x
y
x
y
1
1 0
0 1
0 0 1 1
1
0
0
0 0 1 1
1
0 0
0 0
0 0 1 1
cos sin
sin cos
q q
q q
Translation
P’=TP
Rotation [O]
P’=RP
Scaling [O]
P’=SP
Basic Transformations
Homogeneous Coordinates























1
]
[
1
y
x
T
y
x
If,
























1
]
[
1
1
y
x
T
y
x
then,
)
(
)
(
1
,
1
)
,
(
)
(
)
(
)
,
(
)
,
(
1
1
1
1
h
H
h
H
s
s
S
s
s
S
R
R
t
t
T
t
t
T
x
x
y
x
y
x
y
x
y
x




















q
q
Examples:
Inverse of Transformations
)
,
(
)
,
(
)
,
(
1
)
(
)
(
)
(
)
(
)
,
(
)
,
(
)
,
(
2
1
2
1
y
y
x
x
y
x
y
x
y
y
x
x
y
x
y
x
w
s
w
s
S
w
w
S
s
s
S
R
R
R
R
u
t
u
t
T
u
u
T
t
t
T







q
q
q
q
q
Additional Properties:
Transformation Matrices
Transformation T followed by
Transformation Q followed by
Transformation R: 






















1
]
][
][
[
1
y
x
T
Q
R
y
x
Example: (Scaling with respect to a fixed point)























































x
y
x
y
s
s
x
y
x
y
f
f
x
y
f
f
1
1 0
0 1
0 0 1
0 0
0 0
0 0 1
1 0
0 1
0 0 1 1
Composite Transformations
Order of Transformations
In composite transformations, the order of
transformations is very important.
Order of Transformations
Rotation followed by Translation:
Translation followed by Rotation:
OpenGL postmultiplies the current matrix
with the new transformation matrix
Order of Transformations (OpenGL)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(tx, ty, 0);
glRotatef(theta, 0, 0, 1.0);
glVertex2f(x,y);
Rotation followed by Translation !!
Current Matrix
[ I ]
[ T ]
[ T ] [ R ]
[ T ] [ R ] P
Line Angle Distance Area
Translation Yes Yes Yes Yes
Rotation Yes Yes Yes Yes
Scaling Yes No No No
Reflection Yes Yes Yes Yes
Shear Yes No No Yes
Preserved Attributes
General Properties
A general invertible, linear, transformation.
   
   
 
x a x b y c
y a x b y c
a b a b
1 1 1
2 2 2
1 2 2 1 0
( )
Affine Transformation
Transformation Matrix:










1
0
0
2
2
2
1
1
1
c
b
a
c
b
a
Concatenation.
We perform 2 translations on the same point:
)
,
(
)
,
(
)
,
(
:
expect
we
So
)
,
(
)
,
(
)
,
(
)
,
(
)
,
(
2
1
2
1
2
2
1
1
2
1
2
1
2
2
1
1
2
2
1
1
y
y
x
x
y
x
y
x
y
y
x
x
y
x
y
x
y
x
y
x
d
d
d
d
T
d
d
T
d
d
T
P
d
d
d
d
T
P
d
d
T
d
d
T
P
P
d
d
T
P
P
d
d
T
P





















Concatenation.
?
1
0
0
1
0
0
1
.
1
0
0
1
0
0
1
:
is
)
,
(
)
,
(
product
matrix
The
2
2
1
1
2
2
1
1






















y
x
y
x
y
x
y
x
d
d
d
d
d
d
T
d
d
T
Matrix product is variously referred to as compounding,
concatenation, or composition
Concatenation.
Matrix product is variously referred to as compounding, concatenation, or
composition.


































1
0
0
1
0
0
1
1
0
0
1
0
0
1
.
1
0
0
1
0
0
1
:
is
)
,
(
)
,
(
product
matrix
The
2
1
2
1
2
2
1
1
2
2
1
1
y
y
x
x
y
x
y
x
y
x
y
x
d
d
d
d
d
d
d
d
d
d
T
d
d
T
Properties of translations.
)
,
(
)
,
(
T
4.
)
,
(
)
,
(
)
,
(
)
,
(
3.
)
,
(
)
,
(
)
,
(
2.
)
0
,
0
(
1.
1
-
y
x
y
x
y
x
y
x
y
x
y
x
y
y
x
x
y
x
y
x
s
s
T
s
s
s
s
T
t
t
T
t
t
T
s
s
T
t
s
t
s
T
t
t
T
s
s
T
I
T











Note : 3. translation matrices are commutative.
Homogeneous form of scale.







y
x
y
x
s
s
s
s
S
0
0
)
,
(
Recall the (x,y) form of Scale :











1
0
0
0
0
0
0
)
,
( y
x
y
x s
s
s
s
S
In homogeneous coordinates :
Two-Dimensional Viewing
37
Co-ordinate Systems.
 Cartesian – offsets along the x and y axis from (0.0)
 Polar – rotation around the angle q.
 Graphic libraries mostly using Cartesian co-ordinates
 Any polar co-ordinates must be converted to Cartesian co-
ordinates
 Four Cartesian co-ordinates systems in computer Graphics.
1. Modeling co-ordinates
 2. World co-ordinates
 3. Normalized device co-ordinates
 4. Device co-ordinates
Modeling Coordinates
38
 Also known as local coordinate.
 Ex: where individual object in a scene within separate
coordinate reference frames.
 Each object has an origin (0,0)
 So the part of the objects are placed with reference to the
object’s origin.
 In term of scale it is user defined, so, coordinate values can be
any size.
World Co-ordinates.
39
 The world coordinate system describes the relative positions
and orientations of every generated objects.
 The scene has an origin (0,0).
 The object in the scene are placed with reference to the
scenes origin.
 World co-ordinate scale may be the same as the modeling co-
ordinate scale or it may be different.
 However, the coordinates values can be any size (similar to
MC)
Normalized Device Co-ordinates
40
 Output devices have their own co-ordinates.
 Co-ordinates values:
 The x and y axis range from 0 to 1
 All the x and y co-ordinates are floating point numbers in the
range of 0 to 1
 This makes the system independent of the various devices
coordinates.
 This is handled internally by graphic system without user
awareness.
Device Co-ordinates
41
 Specific co-ordinates used by a device.
 Pixels on a monitor
 Points on a laser printer.
 mm on a plotter.
 The transformation based on the individual device is handled
by computer system without user concern.
Two-Dimensional Viewing
42
Example:
 Graphic program which draw an entire building by an
architect but we only interested on the ground floor
 Map of sales for entire region but we only like to
know from certain region of the country.
Two-Dimensional Viewing
43
 When we interested to display certain portion of the drawing,
enlarge the portion, windowing technique is used
 Technique for not showing the part of the drawing which one is
not interested is called clipping
 An area on the device (ex. Screen) onto which the window will
be mapped is called viewport.
 Window defines what to be displayed.
 A viewport defines where it is to be displayed.
 Most of the time, windows and viewports are usually rectangles
in standard position(i.e aligned with the x and y axes). In some
application, others such as general polygon shape and circles
are also available
 However, other than rectangle will take longer time to process.
Viewing Transformation
44
 Viewing transformation is the mapping of a part of a world-
coordinate scene to device coordinates.
 In 2D (two dimensional) viewing transformation is simply
referred as the window-to-viewport transformation or the
windowing transformation.
 Mapping a window onto a viewport involves converting from
one coordinate system to another.
 If the window and viewport are in standard position, this just
 involves translation and scaling.
 if the window and/or viewport are not in standard, then
extra transformation which is rotation is required.
Viewing Transformation
45
0
1
1
x-world
y-world
window window
Normalised device
world
y-view
x-view
Window-To-Viewport Coordinate Transformation
46
Window-to-Viewport transformation
Window-To-Viewport Coordinate Transformation
47
.
XWmax
YWmax
XWmin
YWmin
XVmax
XVmin
YVmax
YVmin
xw,yw
xv,yv
Window-To-Viewport Coordinate Transformation
48
xv - xvmin = xw - xwmin
xvmax - xvmin xwmax - xwmin
yv – yvmin = yw - ywmin
yvmax – yvmin ywmax - ywmin
From these two equations we derived
xv = xvmin + (xw – xwmin)sx
yv = yvmin + (yw – ywmin)sy
where the scaling factors are
sx = xvmax – xvmin sy = yvmax - yvmin
xwmax – xwmin ywmax - ywmin
Window-To-Viewport Coordinate Transformation
49
The sequence of transformations are:
1. Perform a scaling transformation using a
fixed-point position of (xwmin,ywmin) that
scales the window area to the size of the
viewport.
2. Translate the scaled window area to the
position of the viewport.
Window-To-Viewport Coordinate Transformation
50
 Relative proportions of objects are maintained if the scaling
factors are the same (sx = sy). Otherwise, world objects will be
stretched or contracted in either x or y direction when displayed
on output device.
 How about character strings when map to viewport?
 maintains a constant character size (apply when
standard character fonts cannot be changed).
 If character size can be changed, then windowed will be
applied like other primitives.
 For characters formed with line segments, the mapping
to viewport is carried through sequence of line
transformations .
Viewport-to-Normalized Device Coordinate
Transformation
51
 From normalized coordinates, object descriptions can
be mapped to the various display devices
 When mapping window-to-viewport transformation is
done to different devices from one normalized space, it is
called workstation transformation.
The Viewing Pipeline
52
OpenGL 2D Viewing Functions
• To transform from world coordinate to screen coordinates, the appropriate
matrix mode must be chosen
• glMatrixMode (GL_PROJECTION);
• glLoadIdentity( );
• To define a 2D clipping window, we use OpenGL Utility function:
• gluOrtho2D( xwmin, xwmax, ywmin, ywmax);
• This function also perform normalization (NDC)
53
OpenGL 2D Viewing Functions
• To specify the viewport parameters in OpenGL, we use function
• glViewport(xvmin, yvmin, vpWidth, vpHeight);
54
2D Clipping
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon/Area Clipping
5. Text Clipping
6. Curve Clipping
2D Clipping
1. Introduction:
A scene is made up of a collection of objects specified in world
coordinates
World Coordinates
2D Clipping
When we display a scene only those objects within a particular
window are displayed
wymax
wymin
wxmin wxmax
Window
World Coordinates
2D Clipping
Because drawing things to a display takes time we clip
everything outside the window
wymax
wymin
wxmin wxmax
World Coordinates
Window
1.1 Definition:
– Clipping is the process of determining which elements of
the picture lie inside the window and are visible.
– By default, the “clip window” is the entire canvas
• not necessary to draw outside the canvas
• for some devices, it is damaging (plotters)
• 
– Sometimes it is convenient to restrict the “clip window” to
a smaller portion of the canvas
• partial canvas redraw for menus, dialog boxes, other obscuration
2D Clipping
1.2 Shielding:
– Shielding or exterior clipping is the reverse operation of
clipping where window act as the block used to abstract the
view.
– Examples
• A multi view window system
• The design of page layouts in advertising or publishing
applications or for adding labels or design patterns to
picture.
• Combining graphs, maps o schematics
2D Clipping
2D Clipping
wymax
wymin
wxmin wxmax
Window
World Coordinates
2D Clipping
1.3 Example:
For the image below consider which lines and points should be kept
and which ones should be clipped against the clipping window
wymax
wymin
wxmin wxmax
Window
P1
P2
P3
P6
P5
P7
P10
P9
P4
P8
1.4 Applications:
– Extract part of a defined scene for viewing.
– Drawing operations such as erase, copy, move etc.
– Displaying multi view windows.
– Creating objects using solid modeling techniques.
– Anti-aliasing line segments or object boundaries.
– Identify visible surfaces in 3D views.
2D Clipping
2D Clipping
1.5 Types of clipping:
– Three types of clipping techniques are used depending
upon when the clipping operation is performed
a. Analytical clipping
– Clip it before you scan convert it
– used mostly for lines, rectangles, and polygons, where
clipping algorithms are simple and efficient
2D Clipping
b. Scissoring
– Clip it during scan conversion
– a brute force technique
• scan convert the primitive, only write pixels if inside the clipping
region
• easy for thick and filled primitives as part of scan line fill
• if primitive is not much larger than clip region, most pixels will fall
inside
• can be more efficient than analytical clipping.
2D Clipping
c. Raster Clipping
– Clip it after scan conversion
– render everything onto a temporary canvas and copy the
clipping region
• wasteful, but simple and easy,
• often used for text
2D Clipping
Foley and van Dam suggest the following:
– for floating point graphics libraries, try to use analytical
clipping
– for integer graphics libraries
• analytical clipping for lines and polygons
• others, do during scan conversion
– sometimes both analytical and raster clipping performed
1.6 Levels of clipping:
– Point Clipping
– Line Clipping
– Polygon Clipping
– Area Clipping
– Text Clipping
– Curve Clipping
2D Clipping
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon/Area Clipping
5. Text Clipping
6. Curve Clipping
Point Clipping
– Simple and Easy
– a point (x,y) is not clipped if:
wxmin ≤ x ≤ wxmax
&
wymin ≤ y ≤ wymax
– otherwise it is clipped
wymax
wymin
wxmin wxmax
Window
P1
P2
P5
P7
P10
P9
P4
P8
Clipped
Points Within the Window
are Not Clipped
Clipped
Clipped
Clipped
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon/Area Clipping
5. Text Clipping
6. Curve Clipping
Line Clipping
– It is Harder than point
clipping
– We first examine the end-
points of each line to see
if they are in the window
or not
• Both endpoints inside, line
trivially accepted
• One in and one out, line is
partially inside
• Both outside, might be
partially inside
• What about trivial cases?
ymin
ymax
xmin xmax
Line Clipping
Situation Solution Example
Both end-points inside
the window
Don’t clip
One end-point inside the
window, one outside
Must clip
Both end-points outside
the window
Don’t know!
2D Line Clipping Algorithms
1. Analytical Line Clipping
2. Cohen Sutherland Line Clipping
3. Liang Barsky Line Clipping
Cohen-Sutherland Line Clipping
– 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.
Dr. Ivan E. Sutherland co-
developed the Cohen-
S u t h e r l a n d c l i p p i n g
algorithm. Sutherland is a
graphics giant and includes
amongst his achievements
the invention of the head
m o u n t e d d i s p l a y .
Cohen is something of a mystery – can
a n y b o d y f i n d o u t w h o h e w a s?
Cohen-Sutherland Line Clipping
– Two phases Algorithm
Phase I: Identification Phase
All line segments fall into one of the following categories
1. Visible: Both endpoints lies inside
2. Invisible: Line completely lies outside
3. Clipping Candidate: A line neither in category 1 or 2
Phase II: Perform Clipping
Compute intersection for all lines that are candidate for
clipping.
Cohen-Sutherland Line Clipping
Phase I: Identification Phase: 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
0001
0000
Window
0010
0101 0100 0110
above below right left
3 2 1 0
Region Code Legend
Cohen-Sutherland Line Clipping
Every end-point is labelled with the appropriate region code
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
Cohen-Sutherland Line Clipping
Visible Lines: Lines completely contained within the window
boundaries have region code [0000] for both end-points so are
not clipped
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
Cohen-Sutherland Line Clipping
Invisible Lines: Any line with a common set bit in the region
codes of both end-points can be clipped completely
– The AND operation can efficiently check this
– Non Zero means Invisible
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
Cohen-Sutherland Line Clipping
Clipping Candidates: Lines that cannot be identified as
completely inside or outside the window may or may not cross
the window interior. These lines are processed in Phase II.
– If AND operation result in 0 the line is candidate for clipping
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
Cohen-Sutherland Line Clipping
Assigning Codes
– Let point (x,y) is be given
code b3b2b1b0:
bit 3 = 1 if wymax - y ≤0
bit 2 = 1 if y - wymin ≤ 0
bit 1 = 1 if wxmax - x ≤0
bit 0 = 1 if x - wxmin ≤ 0
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
Cohen-Sutherland Clipping Algorithm
Phase II: Clipping Phase: Lines that are in category 3 are now
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
– 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
Cohen-Sutherland Line Clipping
• 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
– 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
Cohen-Sutherland Line Clipping
• 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 Line Clipping
Example1: Consider the line P9 to P10 below
– Start at P10
– From the region codes
of the two end-points we
know the line doesn’t
cross the left or right
boundary
– Calculate the 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
wymax
wymin
wxmin wxmax
Window
P10 [0100]
P9 [0000]
P10’ [0000]
P9 [0000]
Cohen-Sutherland Line Clipping
Example 2: Consider the line P3 to P4 below
– Start at P4
– From the region codes
of the two end-points
we know the line
crosses the left
boundary so calculate
the intersection point to
generate P4’
– The line P3 to P4’ is completely outside the window so is
clipped
wymax
wymin
wxmin wxmax
Window
P4’ [1001]
P3 [0001]
P4 [1000]
P3 [0001]
Cohen-Sutherland Line Clipping
Example 3: Consider the line P7 to P8 below
– Start at P7
– From the two region
codes of the two
end-points we know
the line crosses the
left boundary so
calculate the
intersection point to
generate P7’
wymax
wymin
wxmin wxmax
Window
P7’ [0000]
P7 [0001] P8 [0010]
P8’ [0000]
Cohen-Sutherland Line Clipping
Example 4: Consider the line P7’ to P8
– Start at P8
– Calculate the
intersection with the
right boundary to
generate P8’
– P7’ to P8’ is inside
the window so is
retained
wymax
wymin
wxmin wxmax
Window
P7’ [0000]
P7 [0001] P8 [0010]
P8’ [0000]
Cohen-Sutherland Line Clipping
Mid-Point Subdivision Method
– Algorithm
1. Initialise the list of lines to all lines
2. Classify lines as in Phase I
i. Assign 4 point bit codes to both end points a3a2a1a0 and b3b2b1b0
ii. If (a3a2a1a0 = b3b2b1b0 = 0 )Line in category 1
iii. If (a3a2a1a0)AND (b3b2b1b0 ) # 0 ) Line in category 2
iv. If (a3a2a1a0)AND (b3b2b1b0 ) = 0 ) Line in category 3
3. Display all lines from the list in category 1 and remove;
4. Delete all lines from the list in category 2 as they are invisible;
5. Divide all lines of category 3 are into two smaller segments at mid-point
(xm,ym) where xm = (x1 +x2)/2 and ym = (y1 +y2)/2
6. Remove the original line from list and enter its two newly created
segments.
7. Repeat step 2-5 until list is null.
Cohen-Sutherland Line Clipping
wymax
wymin
wxmin wxmax
Window
Cohen-Sutherland Line Clipping
Mid-Point Subdivision Method
– Integer Version
– Fast as Division by 2 can be performed by simple shift
right operation
– For NxN max dimension of line number of subdivisions
required log2 N.
– Thus a 1024x1024 raster display require just 10
subdivisions………
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon / Area Clipping
5. Text Clipping
6. Curve Clipping
Polygon Clipping
• Note the difference between clipping lines and
polygons:
NOTE!
Polygon Clipping
• Some difficulties:
– Maintaining correct inside/outside
– Variable number of vertices
– Handle screen corners
correctly
Sutherland-Hodgman Area Clipping
• 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
turns up
again. This
time with
Gary Hodgman with
whom he worked at
the first ever graphics
company Evans &
Sutherland
1. Basic Concept:
• Simplify via separation
• Clip whole polygon against one edge
– Repeat with output for other 3 edges
– Similar for 3D
• You can create intermediate vertices that get thrown
out
Sutherland-Hodgeman Polygon Clipping
Sutherland-Hodgeman Polygon Clipping
• Example
Start Left Right Bottom Top
Note that the point one of the points added when clipping
on the right gets removed when we clip with bottom
2. Algorithm:
Let (P1, P2,…. PN) be the vertex list of the Polygon to be
clipped and E be the edge of +vely oriented, convex clipping
window.
We clip each edge of the polygon in turn against each window
edge E, forming a new polygon whose vertices are determined
as follows:
Sutherland-Hodgeman Polygon Clipping
Four cases
1. Inside: If both Pi-1 and Pi are to the left of window edge
vertex then Pi is placed on the output vertex list.
2. Entering: If Pi-1 is to the right of window edge and Pi is to
the left of window edge vertex then intersection (I) of Pi-1 Pi
with edge E and Pi are placed on the output vertex list.
3. Leaving: If Pi-1 is to the left of window edge and Pi is to the
right of window edge vertex then only intersection (I) of Pi-1
Pi with edge E is placed on the output vertex list.
4. Outside: If both Pi-1 and Pi are to the right of window edge
nothing is placed on the output vertex list.
Sutherland-Hodgeman Polygon Clipping
Sutherland-Hodgeman Polygon Clipping
Creating New Vertex List
out  out
save nothing
Outside
(0 output)
Pi-1
Pi
in  in
save ending vert
Inside
(1 output)
Pi-1
Pi
out  in
save new clip vert
and ending vert
Entering
(2 outputs)
Pi
Pi-1
Pi
in  out
save new clip vert
Leaving
(1 output)
Pi-1
Sutherland-Hodgman Polygon Clipping
• Each example shows the
point being processed (P)
and the previous point (S)
• Saved points define area
clipped to the boundary in
question
S
P
Save Point P
S
P
Save Point I
I
P
S
No Points Saved
S
P
Save Points I & P
I
START
INPUT VERTEX LIST
(P1, P2........, PN)
IF PiPi+1
INTERSECT E ?
FOR i =1 TO (N-1) DO
COMPUTE I
OUTPUT I IN VERTEX LIST
IF Pi TO LEFT
OF E ?
YES NO
YES
OUTPUT Pi IN VERTEX LIST
NO
i = i+1
Flow Chart
Special case for
first Vertex
Flow Chart
Special case for
first Vertex
IF PNP0
INTERSECT
E ?
COMPUTE I
OUTPUT I IN VERTEX
LIST
YES NO
END
YOU CAN ALSO APPEND AN ADDITIONAL VERTEX
PN+1 = P1 AND AVOID SPECIAL CASE FOR FIRST
VERTEX
Sutherland-Hodgeman Polygon Clipping
Inside/Outside Test:
Let P(x,y) be the polygon vertex which is to be tested against
edge E defined form A(x1, y1) to B(x2, y2). Point P is to be said
to the left (inside) of E or AB iff
or C = (x2 – x1) (y – y1) – (y2 – y1)(x – x1) > 0
otherwise it is said to be the right/Outside of edge E
0
1
2
1
1
2
1






x
x
x
x
y
y
y
y
Weiler-Atherton Polygon Clipping
• Problem with Sutherland-Hodgeman:
– Concavities can end up linked
• Weiler-Atherton creates separate polygons in such
cases
Remember
me?
Weiler-Atherton Polygon Clipping
• Example
add clip pt.
and end pt.
add end pt. add clip pt.
cache old dir.
follow clip edge until
a) new crossing
found
b) reach pt. already
added
Weiler-Atherton Polygon Clipping
• Example (cont)
continue from
cached location
add clip pt.
and end pt.
add clip pt.
cache dir.
follow clip edge until
a) new crossing
found
b) reach pt. already
added
Weiler-Atherton Polygon Clipping
• Example (concluded)
continue from
cached location
nothing added
finished
Final result:
Two unconnected
polygons
Weiler-Atherton Polygon Clipping
• Difficulties:
– What if the polygon re-crosses edge?
– How many “cached” crosses?
– Your geometry step must be able to create new polygons
• Instead of 1-in-1-out
Other Area Clipping Concerns
• Clipping concave areas can be a little more tricky as often
superfluous lines must be removed
• Clipping curves requires more work
– For circles we must find the two intersection points on the window
boundary
Window Window
Window Window
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon/Area Clipping
5. Text Clipping
6. Curve Clipping
Text Clipping
Text clipping relies on the concept of bounding
rectangle
TYPES
1. All or None String Clipping
2. All or None Character Clipping
3. Component Character Clipping
Text Clipping
1. All or None String Clipping
• In this scheme, if all of the string is inside window, we clip it,
otherwise the string is discarded. This is the fastest method.
• The procedure is implemented by consider a bounding rectangle
around the text pattern. The boundary positions are compared to
the window boundaries. In case of overlapping the string is
rejected.
STRI NG 1
STRING 3
STRING 4
STRING 5
STRING 4
Text Clipping
2. All or None Character Clipping
• In this scheme, we discard only those characters that are not
completely inside window.
• Boundary limits of individual characters are compared against
window. In case of overlapping the character is rejected.
STRI NG 1
STRING 3
STRING 4
STRING 5
NG 1
TRING 3
STRING 4
Text Clipping
3. Component Character Clipping
• Characters are treated like graphic objects.
– Bit Mapped Fonts : Point Clipping
– Outlined Fonts : Line/Curve Clipping
• In case of overlapping the part of the character inside is displayed
and the outside portion of the character is rejected.
STRI NG 1
STRING 3
STRING 4
STRING 5
NG 1
STRING 4
STRING 3
2D Clipping
1. Introduction
2. Point Clipping
3. Line Clipping
4. Polygon/Area Clipping
5. Text Clipping
6. Curve Clipping
Curve Clipping
– Areas with curved boundaries can be clipped with
methods similar to line and polygon clipping.
– Curve clipping requires more processing as it
involve non linear equations.
– Bounding Rectangles are used to test for overlap
with rectangular clip window.
– If bounding rectangle is completely inside the
object/curve is saved.
– If bounding rectangle is completely outside the
object/curve is discarded.
Curve Clipping
– If both the above tests fails we use other
computation saving approaches depending upon
type of object
• Circle: Use coordinate extent of individual quadrant,
then octant if required.
• Ellipse: Use coordinate extent of individual quadrant.
• Point: Use point clipping
Curve Clipping

More Related Content

What's hot

Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
Mani Kanth
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
Timbal Mayank
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
Aparna Joshi
 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
Kongunadu College of engineering and Technology, Namakkal
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
2013901097
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
Parallel projection
Parallel projectionParallel projection
Parallel projection
Prince Shahu
 
Raster animation
Raster animationRaster animation
Raster animation
abhijit754
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
SwatiHans10
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
Ahmed Daoud
 
Chapter 3 Image Processing: Basic Transformation
Chapter 3 Image Processing:  Basic TransformationChapter 3 Image Processing:  Basic Transformation
Chapter 3 Image Processing: Basic Transformation
Varun Ojha
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
2013901097
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
Alamgir Hossain
 
Image transforms
Image transformsImage transforms
Image transforms
11mr11mahesh
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
 
Sharpening spatial filters
Sharpening spatial filtersSharpening spatial filters
Homogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearingHomogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearing
Manthan Kanani
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
Rabin BK
 
2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
A. S. M. Shafi
 

What's hot (20)

Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
Parallel projection
Parallel projectionParallel projection
Parallel projection
 
Raster animation
Raster animationRaster animation
Raster animation
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
 
Chapter 3 Image Processing: Basic Transformation
Chapter 3 Image Processing:  Basic TransformationChapter 3 Image Processing:  Basic Transformation
Chapter 3 Image Processing: Basic Transformation
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Image transforms
Image transformsImage transforms
Image transforms
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 
Sharpening spatial filters
Sharpening spatial filtersSharpening spatial filters
Sharpening spatial filters
 
Homogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearingHomogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearing
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
 
2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 

Similar to Cs8092 computer graphics and multimedia unit 2

06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
RobinAhmedSaikat
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
sandeep kumbhkar
 
Two dimensionaltransformations
Two dimensionaltransformationsTwo dimensionaltransformations
Two dimensionaltransformations
Nareek
 
2d transformation
2d transformation2d transformation
2d transformation
Sarkunavathi Aribal
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
Ankit Garg
 
1533 game mathematics
1533 game mathematics1533 game mathematics
1533 game mathematics
Dr Fereidoun Dejahang
 
2d transformations
2d transformations2d transformations
2d transformations
rajeshranjithsingh
 
Three dimensional geometric transformations
Three dimensional geometric transformationsThree dimensional geometric transformations
Three dimensional geometric transformations
shanthishyam
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
aravindangc
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)
Amit Kapoor
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
Chandrakant Divate
 
Computer Graphics transformations
Computer Graphics transformationsComputer Graphics transformations
Computer Graphics transformations
swatihans
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
Patel Punit
 
Computer Graphics - transformations in 2d
Computer Graphics - transformations in 2dComputer Graphics - transformations in 2d
Computer Graphics - transformations in 2d
Hisham Al Kurdi, EAVA, DMC-D-4K, HCCA-P, HCAA-D
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
Bala Murali
 
Computer Graphics & linear Algebra
Computer Graphics & linear Algebra Computer Graphics & linear Algebra
Computer Graphics & linear Algebra
Xad Kuain
 
2D-transformation-1.pdf
2D-transformation-1.pdf2D-transformation-1.pdf
2D-transformation-1.pdf
bcanawakadalcollege
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 dxyz120
 
Image Processing 3
Image Processing 3Image Processing 3
Image Processing 3jainatin
 
Lecture 6-1543909797
Lecture 6-1543909797Lecture 6-1543909797
Lecture 6-1543909797
Canh Le
 

Similar to Cs8092 computer graphics and multimedia unit 2 (20)

06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
 
Two dimensionaltransformations
Two dimensionaltransformationsTwo dimensionaltransformations
Two dimensionaltransformations
 
2d transformation
2d transformation2d transformation
2d transformation
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
 
1533 game mathematics
1533 game mathematics1533 game mathematics
1533 game mathematics
 
2d transformations
2d transformations2d transformations
2d transformations
 
Three dimensional geometric transformations
Three dimensional geometric transformationsThree dimensional geometric transformations
Three dimensional geometric transformations
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
 
Computer Graphics transformations
Computer Graphics transformationsComputer Graphics transformations
Computer Graphics transformations
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
 
Computer Graphics - transformations in 2d
Computer Graphics - transformations in 2dComputer Graphics - transformations in 2d
Computer Graphics - transformations in 2d
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Computer Graphics & linear Algebra
Computer Graphics & linear Algebra Computer Graphics & linear Algebra
Computer Graphics & linear Algebra
 
2D-transformation-1.pdf
2D-transformation-1.pdf2D-transformation-1.pdf
2D-transformation-1.pdf
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
 
Image Processing 3
Image Processing 3Image Processing 3
Image Processing 3
 
Lecture 6-1543909797
Lecture 6-1543909797Lecture 6-1543909797
Lecture 6-1543909797
 

More from SIMONTHOMAS S

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
SIMONTHOMAS S
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
SIMONTHOMAS S
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
SIMONTHOMAS S
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
SIMONTHOMAS S
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
SIMONTHOMAS S
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
SIMONTHOMAS S
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
SIMONTHOMAS S
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
SIMONTHOMAS S
 

More from SIMONTHOMAS S (20)

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 

Cs8092 computer graphics and multimedia unit 2

  • 2. CONTENT Two dimensional geometric transformations — Matrix representations and homogeneous coordinates, composite transformations; Two dimensional viewing — viewing pipeline, viewing coordinate reference frame; window-to-viewport coordinate transformation, Two dimensional viewing functions; clipping operations — point, line, and polygon clipping algorithms.
  • 3. Transformation Transform every point on an object according to certain rule. Initial Object Transformed Object P (x,y) Q (x’, y’) x x’ y y’ T The point Q is the image of P under the transformation T.
  • 4. Translation       x x t y y t x y (10,5) (30,5) (20,35) (55,60) (65,30) (45,30) The vector (tx, ty) is called the offset vector.
  • 5. Translation (OpenGL) Specifying a 2D-Translation: glTranslatef(tx, ty, 0.0); (The z component is set to 0 for 2D translation).
  • 6. (x,y) (x’,y’) q       x x y y x y cos sin sin cos q q q q o (x,y) (x’,y’) x y Rotation About the Origin The above 2D rotation is actually a rotation about the z-axis (0,0,1) by an angle q.
  • 7. Rotation About the Origin Specifying a 2D-Rotation about the origin: glRotatef(theta, 0.0, 0.0, 1.0); theta: Angle of rotation in degrees. The above function defines a rotation about the z-axis (0,0,1).
  • 8. (xp , yp) (x,y) (x’,y’) Pivot Point •Pivot point is the point of rotation •Pivot point need not necessarily be on the object Rotation About a Pivot Point
  • 9. (xp , yp) p p y y y x x x     1 1 (x,y) (x1, y1) STEP-1: Translate the pivot point to the origin Rotation About a Pivot Point
  • 10. q q q q cos 1 sin 1 2 sin 1 cos 1 2 y x y y x x     (x1, y1) STEP-2: Rotate about the origin (x2, y2) Rotation About a Pivot Point
  • 11. p p y y y x x x       2 2 STEP-3: Translate the pivot point to original position (x2, y2) (xp, yp) (x’, y’) Rotation About a Pivot Point
  • 12.             x x x y y x y x x y y y p p p p p p ( )cos ( )sin ( )sin ( )cos q q q q Specifying a 2D-Rotation about a pivot point (xp,yp): glTranslatef(xp, yp, 0); glRotatef(theta, 0, 0, 1.0); glTranslatef(-xp, -yp, 0); Note the OpenGL specification of the sequence of transformations in the reverse order ! Rotation About a Pivot Point
  • 13.     x x s y y s x y . . s s x y  Uniform Non-Uniform s s x y  ( , ) s s x y  0 (x,y) (x’,y’) (x,y) (x’,y’) Scaling About the Origin The parameters sx, sy are called scale factors.
  • 14. Specifying a 2D-Scaling with respect to the origin: glScalef(sx, sy, 1.0); sx, sy: Scale factors along x, y. For proper scaling sx, sy must be positive. For 2D scaling, the third scale factor must be set to 1.0. Scaling About the Origin
  • 15. (xf , yf ) f y f f x f y s y y y x s x x x         ). ( ). ( (x,y) (x’,y’) • Translate the fixed point to origin • Scale with respect to the origin •Translate the fixed point to its original position. Scaling About a Fixed Point
  • 16. Reflections Initial Object Reflection about x y =  y x y Reflection about origin x =  x y =  y Reflection about y x =  x
  • 17. Reflections Reflection about x: glScalef(1, -1, 1); Reflection about y: glScalef(-1, 1, 1); Reflection about origin: glScalef(-1, -1, 1);
  • 18. Shear      x x h y y y x •A shear transformation in the x-direction (along x) shifts the points in the x-direction proportional to the y-coordinate. •The y-coordinate of each point is unaffected.
  • 19.                                                                  x y x y t t x y x y x y s s x y x y x y cos sin sin cos q q q q 0 0 Translation Rotation [Origin] Scaling [Origin] Matrix Representations
  • 22. Homogeneous Coordinates To obtain square matrices an additional row was added to the matrix and an additional coordinate, the w-coordinate, was added to the vector for a point. In this way a point in 2D space is expressed in three-dimensional homogeneous coordinates. This technique of representing a point in a space whose dimension is one greater than that of the point is called homogeneous representation. It provides a consistent, uniform way of handling affine transformations.
  • 23. Cartesian Homogeneous 0 ), , , ( , 0 ), , , ( ) , (             c c b a c b c a h h yh xh y x Examples: (5, 8) (15, 24, 3) (x, y) (x, y, 1) Homogeneous Coordinates •If we use homogeneous coordinates, the geometric transformations given above can be represented using only a matrix pre-multiplication. • A composite transformation can then be represented by a product of the corresponding matrices.
  • 27. Transformation T followed by Transformation Q followed by Transformation R:                        1 ] ][ ][ [ 1 y x T Q R y x Example: (Scaling with respect to a fixed point)                                                        x y x y s s x y x y f f x y f f 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 Composite Transformations Order of Transformations
  • 28. In composite transformations, the order of transformations is very important. Order of Transformations Rotation followed by Translation: Translation followed by Rotation:
  • 29. OpenGL postmultiplies the current matrix with the new transformation matrix Order of Transformations (OpenGL) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(tx, ty, 0); glRotatef(theta, 0, 0, 1.0); glVertex2f(x,y); Rotation followed by Translation !! Current Matrix [ I ] [ T ] [ T ] [ R ] [ T ] [ R ] P
  • 30. Line Angle Distance Area Translation Yes Yes Yes Yes Rotation Yes Yes Yes Yes Scaling Yes No No No Reflection Yes Yes Yes Yes Shear Yes No No Yes Preserved Attributes General Properties
  • 31. A general invertible, linear, transformation.           x a x b y c y a x b y c a b a b 1 1 1 2 2 2 1 2 2 1 0 ( ) Affine Transformation Transformation Matrix:           1 0 0 2 2 2 1 1 1 c b a c b a
  • 32. Concatenation. We perform 2 translations on the same point: ) , ( ) , ( ) , ( : expect we So ) , ( ) , ( ) , ( ) , ( ) , ( 2 1 2 1 2 2 1 1 2 1 2 1 2 2 1 1 2 2 1 1 y y x x y x y x y y x x y x y x y x y x d d d d T d d T d d T P d d d d T P d d T d d T P P d d T P P d d T P                     
  • 34. Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition.                                   1 0 0 1 0 0 1 1 0 0 1 0 0 1 . 1 0 0 1 0 0 1 : is ) , ( ) , ( product matrix The 2 1 2 1 2 2 1 1 2 2 1 1 y y x x y x y x y x y x d d d d d d d d d d T d d T
  • 36. Homogeneous form of scale.        y x y x s s s s S 0 0 ) , ( Recall the (x,y) form of Scale :            1 0 0 0 0 0 0 ) , ( y x y x s s s s S In homogeneous coordinates :
  • 37. Two-Dimensional Viewing 37 Co-ordinate Systems.  Cartesian – offsets along the x and y axis from (0.0)  Polar – rotation around the angle q.  Graphic libraries mostly using Cartesian co-ordinates  Any polar co-ordinates must be converted to Cartesian co- ordinates  Four Cartesian co-ordinates systems in computer Graphics. 1. Modeling co-ordinates  2. World co-ordinates  3. Normalized device co-ordinates  4. Device co-ordinates
  • 38. Modeling Coordinates 38  Also known as local coordinate.  Ex: where individual object in a scene within separate coordinate reference frames.  Each object has an origin (0,0)  So the part of the objects are placed with reference to the object’s origin.  In term of scale it is user defined, so, coordinate values can be any size.
  • 39. World Co-ordinates. 39  The world coordinate system describes the relative positions and orientations of every generated objects.  The scene has an origin (0,0).  The object in the scene are placed with reference to the scenes origin.  World co-ordinate scale may be the same as the modeling co- ordinate scale or it may be different.  However, the coordinates values can be any size (similar to MC)
  • 40. Normalized Device Co-ordinates 40  Output devices have their own co-ordinates.  Co-ordinates values:  The x and y axis range from 0 to 1  All the x and y co-ordinates are floating point numbers in the range of 0 to 1  This makes the system independent of the various devices coordinates.  This is handled internally by graphic system without user awareness.
  • 41. Device Co-ordinates 41  Specific co-ordinates used by a device.  Pixels on a monitor  Points on a laser printer.  mm on a plotter.  The transformation based on the individual device is handled by computer system without user concern.
  • 42. Two-Dimensional Viewing 42 Example:  Graphic program which draw an entire building by an architect but we only interested on the ground floor  Map of sales for entire region but we only like to know from certain region of the country.
  • 43. Two-Dimensional Viewing 43  When we interested to display certain portion of the drawing, enlarge the portion, windowing technique is used  Technique for not showing the part of the drawing which one is not interested is called clipping  An area on the device (ex. Screen) onto which the window will be mapped is called viewport.  Window defines what to be displayed.  A viewport defines where it is to be displayed.  Most of the time, windows and viewports are usually rectangles in standard position(i.e aligned with the x and y axes). In some application, others such as general polygon shape and circles are also available  However, other than rectangle will take longer time to process.
  • 44. Viewing Transformation 44  Viewing transformation is the mapping of a part of a world- coordinate scene to device coordinates.  In 2D (two dimensional) viewing transformation is simply referred as the window-to-viewport transformation or the windowing transformation.  Mapping a window onto a viewport involves converting from one coordinate system to another.  If the window and viewport are in standard position, this just  involves translation and scaling.  if the window and/or viewport are not in standard, then extra transformation which is rotation is required.
  • 48. Window-To-Viewport Coordinate Transformation 48 xv - xvmin = xw - xwmin xvmax - xvmin xwmax - xwmin yv – yvmin = yw - ywmin yvmax – yvmin ywmax - ywmin From these two equations we derived xv = xvmin + (xw – xwmin)sx yv = yvmin + (yw – ywmin)sy where the scaling factors are sx = xvmax – xvmin sy = yvmax - yvmin xwmax – xwmin ywmax - ywmin
  • 49. Window-To-Viewport Coordinate Transformation 49 The sequence of transformations are: 1. Perform a scaling transformation using a fixed-point position of (xwmin,ywmin) that scales the window area to the size of the viewport. 2. Translate the scaled window area to the position of the viewport.
  • 50. Window-To-Viewport Coordinate Transformation 50  Relative proportions of objects are maintained if the scaling factors are the same (sx = sy). Otherwise, world objects will be stretched or contracted in either x or y direction when displayed on output device.  How about character strings when map to viewport?  maintains a constant character size (apply when standard character fonts cannot be changed).  If character size can be changed, then windowed will be applied like other primitives.  For characters formed with line segments, the mapping to viewport is carried through sequence of line transformations .
  • 51. Viewport-to-Normalized Device Coordinate Transformation 51  From normalized coordinates, object descriptions can be mapped to the various display devices  When mapping window-to-viewport transformation is done to different devices from one normalized space, it is called workstation transformation.
  • 53. OpenGL 2D Viewing Functions • To transform from world coordinate to screen coordinates, the appropriate matrix mode must be chosen • glMatrixMode (GL_PROJECTION); • glLoadIdentity( ); • To define a 2D clipping window, we use OpenGL Utility function: • gluOrtho2D( xwmin, xwmax, ywmin, ywmax); • This function also perform normalization (NDC) 53
  • 54. OpenGL 2D Viewing Functions • To specify the viewport parameters in OpenGL, we use function • glViewport(xvmin, yvmin, vpWidth, vpHeight); 54
  • 56. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon/Area Clipping 5. Text Clipping 6. Curve Clipping
  • 57. 2D Clipping 1. Introduction: A scene is made up of a collection of objects specified in world coordinates World Coordinates
  • 58. 2D Clipping When we display a scene only those objects within a particular window are displayed wymax wymin wxmin wxmax Window World Coordinates
  • 59. 2D Clipping Because drawing things to a display takes time we clip everything outside the window wymax wymin wxmin wxmax World Coordinates Window
  • 60. 1.1 Definition: – Clipping is the process of determining which elements of the picture lie inside the window and are visible. – By default, the “clip window” is the entire canvas • not necessary to draw outside the canvas • for some devices, it is damaging (plotters) • – Sometimes it is convenient to restrict the “clip window” to a smaller portion of the canvas • partial canvas redraw for menus, dialog boxes, other obscuration 2D Clipping
  • 61. 1.2 Shielding: – Shielding or exterior clipping is the reverse operation of clipping where window act as the block used to abstract the view. – Examples • A multi view window system • The design of page layouts in advertising or publishing applications or for adding labels or design patterns to picture. • Combining graphs, maps o schematics 2D Clipping
  • 63. 2D Clipping 1.3 Example: For the image below consider which lines and points should be kept and which ones should be clipped against the clipping window wymax wymin wxmin wxmax Window P1 P2 P3 P6 P5 P7 P10 P9 P4 P8
  • 64. 1.4 Applications: – Extract part of a defined scene for viewing. – Drawing operations such as erase, copy, move etc. – Displaying multi view windows. – Creating objects using solid modeling techniques. – Anti-aliasing line segments or object boundaries. – Identify visible surfaces in 3D views. 2D Clipping
  • 65. 2D Clipping 1.5 Types of clipping: – Three types of clipping techniques are used depending upon when the clipping operation is performed a. Analytical clipping – Clip it before you scan convert it – used mostly for lines, rectangles, and polygons, where clipping algorithms are simple and efficient
  • 66. 2D Clipping b. Scissoring – Clip it during scan conversion – a brute force technique • scan convert the primitive, only write pixels if inside the clipping region • easy for thick and filled primitives as part of scan line fill • if primitive is not much larger than clip region, most pixels will fall inside • can be more efficient than analytical clipping.
  • 67. 2D Clipping c. Raster Clipping – Clip it after scan conversion – render everything onto a temporary canvas and copy the clipping region • wasteful, but simple and easy, • often used for text
  • 68. 2D Clipping Foley and van Dam suggest the following: – for floating point graphics libraries, try to use analytical clipping – for integer graphics libraries • analytical clipping for lines and polygons • others, do during scan conversion – sometimes both analytical and raster clipping performed
  • 69. 1.6 Levels of clipping: – Point Clipping – Line Clipping – Polygon Clipping – Area Clipping – Text Clipping – Curve Clipping 2D Clipping
  • 70. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon/Area Clipping 5. Text Clipping 6. Curve Clipping
  • 71. Point Clipping – Simple and Easy – a point (x,y) is not clipped if: wxmin ≤ x ≤ wxmax & wymin ≤ y ≤ wymax – otherwise it is clipped wymax wymin wxmin wxmax Window P1 P2 P5 P7 P10 P9 P4 P8 Clipped Points Within the Window are Not Clipped Clipped Clipped Clipped
  • 72. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon/Area Clipping 5. Text Clipping 6. Curve Clipping
  • 73. Line Clipping – It is Harder than point clipping – We first examine the end- points of each line to see if they are in the window or not • Both endpoints inside, line trivially accepted • One in and one out, line is partially inside • Both outside, might be partially inside • What about trivial cases? ymin ymax xmin xmax
  • 74. Line Clipping Situation Solution Example Both end-points inside the window Don’t clip One end-point inside the window, one outside Must clip Both end-points outside the window Don’t know!
  • 75. 2D Line Clipping Algorithms 1. Analytical Line Clipping 2. Cohen Sutherland Line Clipping 3. Liang Barsky Line Clipping
  • 76. Cohen-Sutherland Line Clipping – 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. Dr. Ivan E. Sutherland co- developed the Cohen- S u t h e r l a n d c l i p p i n g algorithm. Sutherland is a graphics giant and includes amongst his achievements the invention of the head m o u n t e d d i s p l a y . Cohen is something of a mystery – can a n y b o d y f i n d o u t w h o h e w a s?
  • 77. Cohen-Sutherland Line Clipping – Two phases Algorithm Phase I: Identification Phase All line segments fall into one of the following categories 1. Visible: Both endpoints lies inside 2. Invisible: Line completely lies outside 3. Clipping Candidate: A line neither in category 1 or 2 Phase II: Perform Clipping Compute intersection for all lines that are candidate for clipping.
  • 78. Cohen-Sutherland Line Clipping Phase I: Identification Phase: 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 0001 0000 Window 0010 0101 0100 0110 above below right left 3 2 1 0 Region Code Legend
  • 79. Cohen-Sutherland Line Clipping Every end-point is labelled with the appropriate region code wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 80. Cohen-Sutherland Line Clipping Visible Lines: Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 81. Cohen-Sutherland Line Clipping Invisible Lines: Any line with a common set bit in the region codes of both end-points can be clipped completely – The AND operation can efficiently check this – Non Zero means Invisible wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 82. Cohen-Sutherland Line Clipping Clipping Candidates: Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior. These lines are processed in Phase II. – If AND operation result in 0 the line is candidate for clipping wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 83. Cohen-Sutherland Line Clipping Assigning Codes – Let point (x,y) is be given code b3b2b1b0: bit 3 = 1 if wymax - y ≤0 bit 2 = 1 if y - wymin ≤ 0 bit 1 = 1 if wxmax - x ≤0 bit 0 = 1 if x - wxmin ≤ 0 wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 84. Cohen-Sutherland Clipping Algorithm Phase II: Clipping Phase: Lines that are in category 3 are now 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 – 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
  • 85. Cohen-Sutherland Line Clipping • 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 – 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
  • 86. Cohen-Sutherland Line Clipping • 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.
  • 87. Cohen-Sutherland Line Clipping Example1: Consider the line P9 to P10 below – Start at P10 – From the region codes of the two end-points we know the line doesn’t cross the left or right boundary – Calculate the 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 wymax wymin wxmin wxmax Window P10 [0100] P9 [0000] P10’ [0000] P9 [0000]
  • 88. Cohen-Sutherland Line Clipping Example 2: Consider the line P3 to P4 below – Start at P4 – From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P4’ – The line P3 to P4’ is completely outside the window so is clipped wymax wymin wxmin wxmax Window P4’ [1001] P3 [0001] P4 [1000] P3 [0001]
  • 89. Cohen-Sutherland Line Clipping Example 3: Consider the line P7 to P8 below – Start at P7 – From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P7’ wymax wymin wxmin wxmax Window P7’ [0000] P7 [0001] P8 [0010] P8’ [0000]
  • 90. Cohen-Sutherland Line Clipping Example 4: Consider the line P7’ to P8 – Start at P8 – Calculate the intersection with the right boundary to generate P8’ – P7’ to P8’ is inside the window so is retained wymax wymin wxmin wxmax Window P7’ [0000] P7 [0001] P8 [0010] P8’ [0000]
  • 91. Cohen-Sutherland Line Clipping Mid-Point Subdivision Method – Algorithm 1. Initialise the list of lines to all lines 2. Classify lines as in Phase I i. Assign 4 point bit codes to both end points a3a2a1a0 and b3b2b1b0 ii. If (a3a2a1a0 = b3b2b1b0 = 0 )Line in category 1 iii. If (a3a2a1a0)AND (b3b2b1b0 ) # 0 ) Line in category 2 iv. If (a3a2a1a0)AND (b3b2b1b0 ) = 0 ) Line in category 3 3. Display all lines from the list in category 1 and remove; 4. Delete all lines from the list in category 2 as they are invisible; 5. Divide all lines of category 3 are into two smaller segments at mid-point (xm,ym) where xm = (x1 +x2)/2 and ym = (y1 +y2)/2 6. Remove the original line from list and enter its two newly created segments. 7. Repeat step 2-5 until list is null.
  • 93. Cohen-Sutherland Line Clipping Mid-Point Subdivision Method – Integer Version – Fast as Division by 2 can be performed by simple shift right operation – For NxN max dimension of line number of subdivisions required log2 N. – Thus a 1024x1024 raster display require just 10 subdivisions………
  • 94. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon / Area Clipping 5. Text Clipping 6. Curve Clipping
  • 95. Polygon Clipping • Note the difference between clipping lines and polygons: NOTE!
  • 96. Polygon Clipping • Some difficulties: – Maintaining correct inside/outside – Variable number of vertices – Handle screen corners correctly
  • 97. Sutherland-Hodgman Area Clipping • 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 turns up again. This time with Gary Hodgman with whom he worked at the first ever graphics company Evans & Sutherland
  • 98. 1. Basic Concept: • Simplify via separation • Clip whole polygon against one edge – Repeat with output for other 3 edges – Similar for 3D • You can create intermediate vertices that get thrown out Sutherland-Hodgeman Polygon Clipping
  • 99. Sutherland-Hodgeman Polygon Clipping • Example Start Left Right Bottom Top Note that the point one of the points added when clipping on the right gets removed when we clip with bottom
  • 100. 2. Algorithm: Let (P1, P2,…. PN) be the vertex list of the Polygon to be clipped and E be the edge of +vely oriented, convex clipping window. We clip each edge of the polygon in turn against each window edge E, forming a new polygon whose vertices are determined as follows: Sutherland-Hodgeman Polygon Clipping
  • 101. Four cases 1. Inside: If both Pi-1 and Pi are to the left of window edge vertex then Pi is placed on the output vertex list. 2. Entering: If Pi-1 is to the right of window edge and Pi is to the left of window edge vertex then intersection (I) of Pi-1 Pi with edge E and Pi are placed on the output vertex list. 3. Leaving: If Pi-1 is to the left of window edge and Pi is to the right of window edge vertex then only intersection (I) of Pi-1 Pi with edge E is placed on the output vertex list. 4. Outside: If both Pi-1 and Pi are to the right of window edge nothing is placed on the output vertex list. Sutherland-Hodgeman Polygon Clipping
  • 102. Sutherland-Hodgeman Polygon Clipping Creating New Vertex List out  out save nothing Outside (0 output) Pi-1 Pi in  in save ending vert Inside (1 output) Pi-1 Pi out  in save new clip vert and ending vert Entering (2 outputs) Pi Pi-1 Pi in  out save new clip vert Leaving (1 output) Pi-1
  • 103. Sutherland-Hodgman Polygon Clipping • Each example shows the point being processed (P) and the previous point (S) • Saved points define area clipped to the boundary in question S P Save Point P S P Save Point I I P S No Points Saved S P Save Points I & P I
  • 104. START INPUT VERTEX LIST (P1, P2........, PN) IF PiPi+1 INTERSECT E ? FOR i =1 TO (N-1) DO COMPUTE I OUTPUT I IN VERTEX LIST IF Pi TO LEFT OF E ? YES NO YES OUTPUT Pi IN VERTEX LIST NO i = i+1 Flow Chart Special case for first Vertex
  • 105. Flow Chart Special case for first Vertex IF PNP0 INTERSECT E ? COMPUTE I OUTPUT I IN VERTEX LIST YES NO END YOU CAN ALSO APPEND AN ADDITIONAL VERTEX PN+1 = P1 AND AVOID SPECIAL CASE FOR FIRST VERTEX
  • 106. Sutherland-Hodgeman Polygon Clipping Inside/Outside Test: Let P(x,y) be the polygon vertex which is to be tested against edge E defined form A(x1, y1) to B(x2, y2). Point P is to be said to the left (inside) of E or AB iff or C = (x2 – x1) (y – y1) – (y2 – y1)(x – x1) > 0 otherwise it is said to be the right/Outside of edge E 0 1 2 1 1 2 1       x x x x y y y y
  • 107. Weiler-Atherton Polygon Clipping • Problem with Sutherland-Hodgeman: – Concavities can end up linked • Weiler-Atherton creates separate polygons in such cases Remember me?
  • 108. Weiler-Atherton Polygon Clipping • Example add clip pt. and end pt. add end pt. add clip pt. cache old dir. follow clip edge until a) new crossing found b) reach pt. already added
  • 109. Weiler-Atherton Polygon Clipping • Example (cont) continue from cached location add clip pt. and end pt. add clip pt. cache dir. follow clip edge until a) new crossing found b) reach pt. already added
  • 110. Weiler-Atherton Polygon Clipping • Example (concluded) continue from cached location nothing added finished Final result: Two unconnected polygons
  • 111. Weiler-Atherton Polygon Clipping • Difficulties: – What if the polygon re-crosses edge? – How many “cached” crosses? – Your geometry step must be able to create new polygons • Instead of 1-in-1-out
  • 112. Other Area Clipping Concerns • Clipping concave areas can be a little more tricky as often superfluous lines must be removed • Clipping curves requires more work – For circles we must find the two intersection points on the window boundary Window Window Window Window
  • 113. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon/Area Clipping 5. Text Clipping 6. Curve Clipping
  • 114. Text Clipping Text clipping relies on the concept of bounding rectangle TYPES 1. All or None String Clipping 2. All or None Character Clipping 3. Component Character Clipping
  • 115. Text Clipping 1. All or None String Clipping • In this scheme, if all of the string is inside window, we clip it, otherwise the string is discarded. This is the fastest method. • The procedure is implemented by consider a bounding rectangle around the text pattern. The boundary positions are compared to the window boundaries. In case of overlapping the string is rejected. STRI NG 1 STRING 3 STRING 4 STRING 5 STRING 4
  • 116. Text Clipping 2. All or None Character Clipping • In this scheme, we discard only those characters that are not completely inside window. • Boundary limits of individual characters are compared against window. In case of overlapping the character is rejected. STRI NG 1 STRING 3 STRING 4 STRING 5 NG 1 TRING 3 STRING 4
  • 117. Text Clipping 3. Component Character Clipping • Characters are treated like graphic objects. – Bit Mapped Fonts : Point Clipping – Outlined Fonts : Line/Curve Clipping • In case of overlapping the part of the character inside is displayed and the outside portion of the character is rejected. STRI NG 1 STRING 3 STRING 4 STRING 5 NG 1 STRING 4 STRING 3
  • 118. 2D Clipping 1. Introduction 2. Point Clipping 3. Line Clipping 4. Polygon/Area Clipping 5. Text Clipping 6. Curve Clipping
  • 119. Curve Clipping – Areas with curved boundaries can be clipped with methods similar to line and polygon clipping. – Curve clipping requires more processing as it involve non linear equations. – Bounding Rectangles are used to test for overlap with rectangular clip window.
  • 120. – If bounding rectangle is completely inside the object/curve is saved. – If bounding rectangle is completely outside the object/curve is discarded. Curve Clipping
  • 121. – If both the above tests fails we use other computation saving approaches depending upon type of object • Circle: Use coordinate extent of individual quadrant, then octant if required. • Ellipse: Use coordinate extent of individual quadrant. • Point: Use point clipping Curve Clipping