Clipping & Viewing (1)
Clipping & Viewing (1)
Clipping & Viewing (1)
1
2D Viewing Transformation
Clipping Window
ywmax
World Coordinates
xwmin xwmax
Viewing world has its own
Viewport
yvmax coordinates, which may be
a non-uniform scaling of
world coordinates.
yvmin
Viewport Coordinates
xvmin xvmax
2
Clipping Algorithms
p9
Before Clipping After Clipping
p4 p10
p2 p2
p1 p1
p8
p6 p6 p8
p3 p5 p5
p7 p7
4
Cohen-Sutherland Line Clipping Algorithm
• Step 1:
5
Top bit Bottom bit Right bit Left bit
x xwmin xwmax x
1 0 0 1 1 0 0 0 1 0 1 0
ywmax y
0 0 0 1 0 0 0 0 0 0 1 0
y ywmin
0 1 0 1 0 1 0 0 0 1 1 0
Endpoint codes are 0000 for both iff line is completely inside.
If endpoint codes has 1 in same bit, line is certainly outside.
6
• Step 2:
• The intersection points with a clipping boundary can be calculuted
using the slope-intercept form of the line equation.
• Eq. for line passing through points P1 (x1, y1) and P2 (x2, y2) is
• Intersections with the clipping boundaries of the window are given
as :
– Where t is parameter
• Consider convex clipping region R
• f is boundary point of the convex region R
• n is inner normal for one of its boundaries (See fig.)
13
• If dot product is negative, i.e.
n . [ P(t) - f ] < 0
then the vector [P(t)-f ] is pointed away from the interior of R.
• If dot product is zero, i.e.
n . [ P(t) - f ] = 0
then the vector [P(t)-f ] perpendicular to normal n
• If dot product is positive, i.e.
n . [ P(t) - f ] > 0
then the vector [P(t)-f] is pointed towards the interior of R( See Fig)
14
Sutherland-Hodgman Polygon Clipping
1
1’’ 1’’
1’ 3’’ 1’ 3’’
Clipping
Clipping Window 3
3’ 3’
2’ 2’’ 2’ 2’’
2
• Efficient algorithm for clipping convex polygons.
15
The four possible outputs generated by the left clipper, depending on
the relative position of pair of edge endpoints.
out in in in
v2
output: v1v 2 output: v 2
v2 v1
v1
v1
out out
v1
v1 output: none
v2 v1
in out
output: v1
v2
16
2
2’
3 2”
1’
3’
1
Input Left Clipper Right Clipper Bottom Clipper Top Clipper
[1,2]: (in-in)>{2}
17
• The four clippers can work in parallel.
– Once a pair of endpoints it output by the first clipper,
the second clipper can start working.
– The more edges in a polygon, the more effective
parallelism is.
18
3D Viewing Concepts
May 2010 19
Clipping window: Selects what we want to see.
Viewport: Indicates where it is to be viewed on the output
device (still in world coordinates).
Display window: Setting into screen coordinates.
Construct World-
Coordinate Scene Convert World-
Coordinates to Projection
From Modeling-
Coordinate Viewing- Transformation
Transformations Coordinates
Projection Coordinates
May 2010 21
Model is given in model (self) coordinates.
Conversion to world coordinates takes place.