Documente Academic
Documente Profesional
Documente Cultură
TWO DIMENSIONAL
VIEWING
Two-Dimensional Viewing
Co-ordinate Systems.
Modeling Coordinates
World Co-ordinates.
Co-ordinates values:
Device Co-ordinates
Pixels on a monitor
Points on a laser printer.
mm on a plotter.
Two-Dimensional Viewing
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
Viewing Transformation
Viewing Transformation
y-world
y-view
window
x-view
x-world
world
window
Normalised device
Window-to-Viewport transformation
YWmax
YVmax
.
xw,yw
YWmin
XWmin
YVmin
XWmax
xv,yv
XVmin
XVmax
xv - xvmin
xvmax - xvmin
yv yvmin
yvmax yvmin
xw - xwmin
xwmax - xwmin
=
yw - ywmin
ywmax - ywmin
sy = yvmax - yvmin
ywmax - ywmin
Clipping
Any procedure that identifies those portions of a
Window
A scene is made up of a collection of objects specified
in world coordinates
World Coordinates
Window
contd
wymin
wxmax
wxmin
World Coordinates
Window contd..
Because drawing things to a display takes time we
wymin
wxmax
wxmin
World Coordinates
Clipping Operation
For the image below if we want to know which lines and
to be clipped.
Point Clipping
P4
Line Clipping
Window
wymax
P6
P3
P7
P2
P1
P5
P9
P8
min
Text Clipping
P10
wxmin
wxmax
Point Clipping
Solution is easy - a point (x,y) is not clipped if:
P4 Clipped
Window
wymax
Clipped
P7
wymin
Clipped
P5
P2
P1
P10
wxmin
Clipped
P8
Clipped
wxmax
Line Clipping
before clipping
after clipping
Line Clipping
Examine the end-points of each line to see if they are
Solution
Must clip
Both end-points
outside the window
Dont know!
Example
be performed as follows:
computationally expensive
Because a scene can contain so many lines, the
brute force approach to clipping is much too slow
0u1
Example
Solve u by substitute x = xwmax in
x = x1 + u (x2 x1)
5 = 4 + u (7 4)
u = 1/3
The value of u is within the range from 0 to 1, the line
0
left
Bottom bit
Right bit
Left bit
xwmax x
x xwmin
1
ywmax y
0
y ywmin
0
region code
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P12 [0010]
P5 [0000]
P7 [0001]
P9 [0000]
wymin
P13 [0101]
wxmin
P8 [0010]
P10 [0100]
wxmax
P14 [0110]
boundaries have region code [0000] for both endpoints so are not clipped
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P12 [0010]
P5 [0000]
P7 [0001]
P9 [0000]
wymin
P13 [0101]
wxmin
P8 [0010]
P10 [0100]
wxmax
P14 [0110]
P4 [1000]
p11 : 1010
p12 : 0010
Window
wymax
P6 [0000]
P3 [0001]
P12 [0010]
P5 [0000]
P7 [0001]
P9 [0000]
wymin
P13 [0101]
wxmin
P8 [0010]
P10 [0100]
wxmax
P14 [0110]
wymax
Window
Start at P10
From the region codes
of the two end-points we
P [0000]
wymin
know the line doesnt
P [0000]
cross the left or right
P [0100]
boundary
wxmin
wxmax
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
10
10
wxmax
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
Window
wymax
P7 [0000]
P8 [0010]
P7 [0001]
P8 [0000]
wymin
wxmin
wxmax
Another Example
p2
1
p2
p2
p3
p1
p3
0
p4
p1
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)
x = x1 + (yboundary - y1) / m
xwmax
ywmax
ywmin
y = y1 + u y,
0 u 1
where x= x2 x1 and y= y2 y1
ywmin y1 + u y ywmax
q1 = x1 xwmin
p2 = x,
q2 = xwmax x1
p3 = y,
q3 = y1 ywmin
p4 = y,
q4 = ywmax y1
u = q k / pk
Liang-Barsky Line
summarized as follows:
Clipping
Algorithm
p1 = x, q1 = x1 xwmin, r1 = q1/ p1
p2 = x, q2 = xwmax x1 , r2 = q2/ p2
p3 = y, q3 = y1 ywmin, r3 = q3/ p3
p4 = y, q4 = ywmax y1, r1 = q4/ p4
can
be
which the line proceeds from inside to the outside (pk >
0). A value of rk is calculated for each of these boundaries,
and the value of u2 is the minimum of the set consisting
of 1 and the calculated r values.
5. Otherwise,
If u2 <1
Otherwise
If u1 >0
Otherwise
x= x1+u2 x,
x = x2 ,
x= x1+u1 x,
x = x1 ,
y = y1 +u2 y
y = y2
y = y1 +u1 dy
y = y1
P0
P0
B
Pend is outside,
we set up the four regions shown in
Fig. The
intersection with the
appropriate window boundary is
Pend
LT
compared to P0 , Pcorner
L
L
P0
LR
L
LB
Pend
TR
L
L
T
T
LB
TR
L
LB
LR
TB
TR
L
L
T
T
TR
LB
LR
LB
TB
Right
Clipper
Bottom
Clipper
Then,
polygon-processing
counterclockwise)
direction
(clockwise
or
following rules:
Text Clipping
There are several techniques that can be used to provide
The
Text Clipping
All-or-none string-clipping
If all of the string is inside a clip window, we keep it.
Otherwise the string is discarded.
Text Clipping
All-or-none character-clipping
Here we discard only those characters that are not
Text Clipping
Clip the components of individual characters
We treat characters in much the same way that we treated
lines.
we clip off the parts of the character that are outside the
window