5. Reflection
• Reflection can be generalized to any reflection
point in xy-plane. This reflection is the same as a
180o rotation in the xy plane using the reflection
point as the pivot point.
• If we choose the reflection point as the diagonal
line x=y, the reflection matrix is
1
0
0
0
0
1
0
1
0
y
x
y=x
6. Reflection
• We can derive this matrix by concatenating a sequence of rotation and coordinate-
axis reflection matrices. One possible sequence is: a) clockwise rotation of 45o (b)
reflection about x-axis (c) counterclockwise rotation by 45o.
• To obtain a transformation matrix for reflection about the diagonal y = -x, we could
concatenate matrices for the transformation sequence: a) clockwise rotation of 45o (b)
reflection about y-axis (c) counterclockwise rotation by 45o. The resulting
transformation is:
• Reflections about any line y=mx + c in the xy plane can be accomplished with a
combination of translate-rotate-reflect transformations.
1
0
0
0
0
1
0
1
0
7. Shear
• A shearing affects an object in a particular direction (in 2D, it’s either in the x or in
the y direction)
• 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.
y
y
y
h
x
x x
8. Shear along x
Matrix Representations
Shear along y
1
0
0
0
1
0
0
1
1
0
1
1
0
0
0
1
0
0
1
1
0
1
h
y
x
h
y
x
h
y
x
h
y
x
Shear along x (homogeneous coordinate)
Shear along y (homogeneous coordinate)
9. Shearing
• A shear in the x direction would be as follows:
x’ = x + h. y & y’ = y
h is shear parameter
• The quantity h specifies what fraction of the y-
coordinate should be added to the x-coordinate,
and may be positive or negative
• -ve values for h shifts coordinate positions to the
left
11. • We generate x-direction shears relative to other reference lines with
• With coordinate positions transformed as
x’ = x + h(y- yref), y’ = y
• We generate y-direction shears relative to other reference lines (eg. x = xref) with
• With coordinate positions transformed as
x’ = x & y’ = h(x- xref) + y,
1
0
0
0
1
0
.
1 ref
y
h
h
1
0
0
.
1
0
0
1
ref
x
h
h
13. 2D Viewing Pipeline
Construct World Coordinate
Scene Using Model-
Coordinate Transformations
Convert World Coordinates to
Viewing Coordinates
Transform Viewing
Coordinates to Normalized
Coordinates
Map Normalized Coordinates
to Device Coordinates
Modeling coordinates
World coordinates
Viewing coordinates
Normalized coordinates
Device coordinates
From Computer Graphics by Hearn & Baker
14.
15.
16. Coordinate Systems
• Screen coordinates: the coordinate system used
to address the screen (device coordinates)
• World coordinates: a user defined application
specific coordinate system having its own units
of measure, axis, origin etc.
• Window: the rectangular region of the world
that is visible
• Viewport: the rectangular region of the screen
space that is used to display the window.
23. (xmin, ymin)
(xmax, ymax)
x = xmin x = xmax
y = ymin
y = ymax
(x1, y1)
clip
rectangle
max
min
max
min
y
y
y
x
x
x
For a point (x,y) to be inside the clip rectangle:
Point Clipping
26. Cases for clipping lines
D
A
B
C
D'
A
B
C
D'
clip
rectangle
Line Clipping
27. Cases for clipping lines
D
E
F
A
B
C
D'
A
B
C
D'
clip
rectangle
Line Clipping
28. Cases for clipping lines
D
E
F
A
B
C
D'
G
H
G'
H'
A
B
C
D'
G'
H'
clip
rectangle
Line Clipping
29. Cases for clipping lines
D
E
F
A
B
C
D'
G
H
G'
H'
I
J
I'
J'
A
B
C
D'
G'
H'
clip
rectangle
Line Clipping
30. Cohen-Sutherland Clipping
Basic Idea
– Encode the line endpoints
– Successively divide the line segments so
that they are completely contained in the
window or completely lies outside window
– Division occurs at the boundary of window
1000
0010
1010
0110
0100
0101
0001
1001
0000
left
right
bottom
top
31. Four Cases
– outcode1 = outcode2 = 0000 --> Accept all
– outcode1 OR outcode2 = 0000 --> Accept all
– outcode1 & outcode2 != 0000 --> Discard
– outcode1 != 0000 , outcode2 = 0000 (Vice versa)
--> Shorten
– outcode1 & outcode2 = 0000 --> Discard or Shorten
A
B
C
D
E
F
G
H
I
J
32. 1. A line segment can be trivially accepted
if the outcodes of both the endpoints are
zero.
2. A line segment can be trivially rejected if
the logical AND of the outcodes of the
endpoints is not zero.
3. A key property of the outcode is that bits
that are set in nonzero outcode
correspond to edges crossed.
Cohen-Sutherland Algorithm
33. • The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a
line to determine whether intersection calculations can be avoided.
1. First, end-point pairs are checked for Trivial Acceptance.
2. If the line cannot be trivially accepted, region checks are done for
Trivial Rejection.
3. If the line segment can be neither trivially accepted or rejected, it is
divided into two segments at a clip edge, so that one segment can be
trivially rejected.
– These three steps are performed iteratively until what remains can be
trivially accepted or rejected.
Cohen-Sutherland Algorithm
38. For a line {(x1, y1), (x2, y2)}
The y coordinate of the intersection point
with the vertical boundary is
y=y1+m(x-x1)
Where x=xwmin or xwmax
m=(y2-y1)/(x2-x1)
Intersection with horizontal boundary
x= x1+(y-y1)/m
With y=ywmin or ywmax
39. (1) This is fundamentally different (from Cohen-
Sutherland algorithm) and generally more efficient
algorithm was originally published by Cyrus and
Beck.
(2) Liang and Barsky later independently developed a
more efficient algorithm that is especially fast in the
special cases of upright 2D and 3D clipping
regions.They also introduced more efficient trivial
rejection tests for general clip regions.
Parametric Line-Clipping
50. Liang-Barsky Clipping
• The Liang-Barsky two-dimensional line
clipping algorithm uses the parametric
form of a line and the clipping window to
determine the clipping coordinates of lines
intersecting the clipping volume.
• This algorithm is significantly more
efficient than Cohen-Sutherland clipping.
51. Liang-Barsky Clipping
• To summarize, the Liang-Barsky clipping algorithm
consists of the following steps:
1. Define all line segments in parametric form.
2. Set the minimum and maximum values for u (umin = 0 and
umax = 1).
3. Calculate all the u values located between umin and umax.
4. Determine whether the arbitrary values of each parametric
line lie within the clipping window.
a. If the line intersects, shorten the line segment via a floating-point
division.
b. If the line doesn’t intersect the clipping window, discard it.
5. Display all clipped line segments.
57. Clipping Polygons
• Extending two-dimensional line clipping to
polygons involves the clipping of polygons
against a clipping rectangle or against other
polygons, as is the case with hidden surface
removal.
• Polygon clipping algorithms are derived from
simple line clipping algorithms.
• We can thus clip a polygon against the edges of
a clipping rectangle.
• There is, however, a problem with this approach
– clipping concave polygons can result in several
additional polygons as shown in Figure 12-19.
59. Clipping Polygons
• The illustrated problem is not encountered when
working with convex polygons.
• The only solution to this problem is to consider
the clipped region as a single polygon or to
tessellate (divide) the polygon into a number of
convex polygons
61. Sutherland-Hodgman Polygon Clipping
• Input each edge (vertex pair) successively.
• Output is a new list of vertices.
• Each edge goes through 4 clippers.
• The rule for each edge for each clipper is:
– If first input vertex is outside, and second is inside,
output the intersection and the second vertex
– If first both input vertices are inside, then just output
second vertex
– If first input vertex is inside, and second is outside,
output is the intersection
– If both vertices are outside, output is nothing
62. Sutherland-Hodgman Polygon Clipping:
Four possible scenarios at each clipper
outside inside
v1
v1’
v2
outside inside
v1
v2
outside inside
v1
v1’
v2
outside inside
v1
v2
Outside to inside:
Output: v1’ and v2
Inside to inside:
Output: v2
Inside to outside:
Output: v1’
Outside to outside:
Output: nothing
68. Input vertex P
First Point Yes
No
F=P
Does SP intersect
E?
No
Yes
Compute
Intersection Point
I
Output
vertex I
S=P
Is S on left
side of E?
Exit
NO
Yes
Output
vertex S
Close Polygon entry
Does SF
intersect E?
Compute
Intersection I
Yes
Output
vertex I
Exit
No