2 DViewing
2 DViewing
Introduction
Introduction
Examples:
Graphics program which draw an entire
building by an architect but we are only
interested on the ground floor
Map of sales for entire country but we only like
to know from certain region of the country.
Viewport
2D Viewing
2D viewing transformation is a mapping of world
coordinate scene to device coordinates
window
yvmax
ywmax
viewport
yvmin
ywmin
xvmin
xwmin
xvmax
xwmax
world coordinates
viewing coordinates
Coordinate Representations
Modeling co-ordinates
World co-ordinates
Normalized device co-ordinates
Device co-ordinates
Modeling co-ordinates
Local coordinates.
where individual object in a scene
within separate coordinate frames
Each object has an origin (0,0)
The part of the objects are placed
with reference to the objects origin.
World co-ordinates
Device co-ordinates
Pixels on a monitor
Points on a laser printer
2D Viewing Transformation
1.
2.
3.
4.
2D Viewing Transformation
Pipeline
Modeling coordinate
Construct world coordinate scene using
modeling coordinate transformation
World Coordinate
yw
yv
viewing coordinates
V is view up
vector(orientation)
v
y0
xv
x0
world coordinates
xw
xv
xw
yw
yv
xv
xw
MWC,VC = R.T
R->Rotation matrix
T->Translation matrix
1
window
yvmax
ywmax
viewport
(xv, yv)
(xw, yw)
yvmin
ywmin
0
xwmin
xvmin
xvmax
xwmax
world coordinates
viewing coordinates
xvmax xvmin
xwmax xwmin
yv yvmin
yw ywmin
yvmax yvmin
ywmax ywmin
xv max xv min
xwmax xwmin
sy
yv max yv min
ywmax ywmin
xv xv min ( xw xwmin ) s x
yv yv min ( yw ywmin ) s y
Zooming:
By successively mapping different sized windows
on to a fixed size view port.
Panning:
By moving a fixed size window across various
objects in a scene
2D Clipping
2D Clipping Algorithms
Point Clipping
Line Clipping
Point Clipping
ywmax
P will be displayed if
xwmin x xwmax and
ywmin y ywmax
P=(x,y)
ywmin
xwmin
xwmax
Line Clipping
Before Clipping
After Clipping
Line Clipping
If both endpoints are inside of all 4
clipping boundaries => inside
If both endpoints are outside any
one of the 4 boundaries
=> outside
Otherwise, line intersects at least
one boundary and it may or may
not cross the window ;
intersections needs to be
calculated
Line Clipping
If one or both endpoints is outside
the window, the parametric
representation could be used to
determine values of parameter u
for intersection with the boundary
coordinates.
x = x0 + u(xend x0)
y = y0 + u(yend y0)
if 0 u 1 part of the line is inside
Requires good deal of
computation
(xend,yend)
(x,y)
(x0,y0)
1001
1000
1010
0001
0000
0010
0101
0100
0110
Polygon Clipping
Polygon Clipping
Polygon Clipping
To clip a polygon:
Polygon Clipping
Various Cases
Following tests are conducted as
each pair of adjacent polygon
vertices are passed to a window
boundary clipper.
1. First vertex is outside the window
border and second vertex is inside
=> send the intersection point and
the second vertex to the next clipper
2. Both vertices are inside
=> send only the second vertex
v1
v2
v1
v2
v1
Various Cases
v1
v2
v1
v1
v2
Example
Example
Left boundary
Sutherland-Hodgman Polygon
Clipping
Concave Polygons
or