This document discusses two-dimensional graphics transformations and matrix representations. It covers topics such as translation, rotation, scaling, reflections, shearing, and representing composite transformations using matrix multiplication. Homogeneous coordinates are also introduced as a way to represent 2D points using 3-dimensional vectors and matrices for transformations.
with today's advanced technology like photoshop, paint etc. we need to understand some basic concepts like how they are cropping the image , tilt the image etc.
In our presentation you will find basic introduction of 2D transformation.
This Ppt is based on the Raster animation . It explains u ablout a brief idea bout the Raster Graphics its Working with Real time Animation Examples that are used in our day to day life.
The following points are covered in this ppt
1. Introduction
2. Working of Raster Animation
3. Types of Raster Animations Modern and Traditional
4. Examples
5.Applications
6. Advantages
7. Disadvantages
Computer graphics lab report with code in cppAlamgir Hossain
This is the lab report for computer graphics in cpp language. Basically this course is only for the computer science and engineering students.
Problem list:
1.Program for the generation of Bresenham Line Drawing.
2. Program for the generation of Digital Differential Analyzer (DDA) Line Drawing.
3. Program for the generation of Midpoint Circle Drawing.
4. Program for the generation of Midpoint Ellipse Drawing.
5. Program for the generation of Translating an object.
6. Program for the generation of Rotating an Object.
7. Program for the generation of scaling an object.
All programs are coaded in cpp language .
its very useful for students.
Sharpening process in spatial domain
Direct Manipulation of image Pixels.
The objective of Sharpening is to highlight transitions in intensity
The image blurring is accomplished by pixel averaging in a neighborhood.
Since averaging is analogous to integration.
Prepared by
M. Sahaya Pretha
Department of Computer Science and Engineering,
MS University, Tirunelveli Dist, Tamilnadu.
All the information regarding 3D viewing is here. The whole presentation consists mainly of 3D viewing pipeline. This slide will make you clear about how one can have a 3d viewing of an object.
with today's advanced technology like photoshop, paint etc. we need to understand some basic concepts like how they are cropping the image , tilt the image etc.
In our presentation you will find basic introduction of 2D transformation.
This Ppt is based on the Raster animation . It explains u ablout a brief idea bout the Raster Graphics its Working with Real time Animation Examples that are used in our day to day life.
The following points are covered in this ppt
1. Introduction
2. Working of Raster Animation
3. Types of Raster Animations Modern and Traditional
4. Examples
5.Applications
6. Advantages
7. Disadvantages
Computer graphics lab report with code in cppAlamgir Hossain
This is the lab report for computer graphics in cpp language. Basically this course is only for the computer science and engineering students.
Problem list:
1.Program for the generation of Bresenham Line Drawing.
2. Program for the generation of Digital Differential Analyzer (DDA) Line Drawing.
3. Program for the generation of Midpoint Circle Drawing.
4. Program for the generation of Midpoint Ellipse Drawing.
5. Program for the generation of Translating an object.
6. Program for the generation of Rotating an Object.
7. Program for the generation of scaling an object.
All programs are coaded in cpp language .
its very useful for students.
Sharpening process in spatial domain
Direct Manipulation of image Pixels.
The objective of Sharpening is to highlight transitions in intensity
The image blurring is accomplished by pixel averaging in a neighborhood.
Since averaging is analogous to integration.
Prepared by
M. Sahaya Pretha
Department of Computer Science and Engineering,
MS University, Tirunelveli Dist, Tamilnadu.
All the information regarding 3D viewing is here. The whole presentation consists mainly of 3D viewing pipeline. This slide will make you clear about how one can have a 3d viewing of an object.
Mathematics (from Greek μάθημα máthēma, “knowledge, study, learning”) is the study of topics such as quantity (numbers), structure, space, and change. There is a range of views among mathematicians and philosophers as to the exact scope and definition of mathematics
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
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.
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
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
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.
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
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