Professional Documents
Culture Documents
Topics
Interactive Graphic Systems
Drawing lines
Drawing circles
Filling polygons
ApplicationProgram
Program
Application
GraphicsSystem
System
Graphics
Application Program
Creates, stores into, and retrieves from the application
model
Handles user-inputs
Sends output commands to the graphics system:
Which geometric object to view (point, line, circle,
polygon)
How to view it (color, line-style, thickness, texture)
Graphics System
Intermediates between the application program
and the interface hardware:
Output flow
Input flow
Causes the application program to be deviceindependent.
Display Hardware
CRT - Cathode Ray Tube
Cathode
(electron gun)
focusing
anode
shadow mask
and phosphor
coated screen
deflection
yoke
electron guns
shadow mask
phosphors on
glass screen
Scan line
Display Hardware
FED - Field Emission Display
Anode
Phospor
Microtips
(Emitters)
Catode electrodes
pixel
Raster Display
Interaction
data
Display
commands
Keyboard
Mouse
Display
Controller
Graphics
system
155
255
0
1
17
45
66
95
82
78
27
147
55
12
159
36
Frame Buffer
Video
Controller
Terminology
Pixel: Picture element.
- Smallest accessible element in picture
- Assume rectangular or circular shape
Aspect Ratio: Ratio between physical dimensions of a pixel (not necessarily 1)
Dynamic Range: The ratio between the minimal (not zero!) and the maximal
light intensity a display pixel can emit
Resolution: The number of distinguishable rows and columns in the device.
Measured in:
- Absolute values (1K x 1K) or,
- Density values (300 dpi [=dots per inch])
Screen Space: A discrete Cartesian coordinate system of the screen pixels
Object Space: The Cartesian coordinate system of the universe, in which the
objects (to be displayed) are embedded
Scan Conversion
The conversion from a geometrical
representation of an object to pixels in a
raster display
(x1,y1)
(x0,y0)
Representations
Implicit formula:
Constraint(s) expressed as
f(x,y,..)=0
fi(x1,x2,..,xn)=0 ; i=1..n-k
Explicit formula:
For each x define y as y=f(x)
Good only for "functions".
Parametric formula:
Depending on free parameter(s)
x=fx(t)
y=fy(t)
Line in 2 dimensions
Implicit representation:
x + y +
Explicit representation:
y = mx + B
Parametric representation:
x
P =
y
= 0
y1 y 0
m =
x1 x 0
P = P0 + ( P1 P0 ) t
P1
y1
x0
x1
B
P0
t [ 0 .. 1 ]
y0
y = mx + B
y1 - y0
x1 - x0
offset= B = y1-mx1
slope = m =
(x0,y0)
Assume |m| 1
Assume x0 x1
Basic Algorithm
For x = x0 to x1
y = mx + B
PlotPixel(x,round(y))
end;
For each iteration: 1 float multiplication, 1 addition, 1 round
yi+1 = yi + m
Algorithm
y=y0
For x = x0 to x1
PlotPixel(x,round(y))
y= y + m
end;
( xi+1,Round(yi+m) )
( xi, yi )
( xi,Round(yi) )
( xi+1, yi+m )
Symmetric Cases:
if x0 > x1 for |m| 1 or y0 > y1 for |m| 1
swap((x0,y0),(x1,y1))
NE
Q
M
(xp,yp)
dy
x+B
dx
(a>0)
f(x,y) < 0
f(x,y) = 0
f(x,y) > 0
Decision Variable :
d = f(M) = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c
choose NE if d > 0
choose E if d 0
NE
M
M
M
E
(xp,yp)
If E was chosen at xp + 1
If NE was chosen at xp + 1
Enhancement:
To eliminate fractions, define:
f(x,y) = 2(ax + by + c) = 0
dstart =2dy - dx
E=2dy
NE=2(dy-dx)
+ y
= 0
Explicit representation:
y =
Parametric representation:
x R cos
=
y R sin
(t )
(t )
t [ 0 .. 2 ]
(y,x)
(-y,-x)
(y,-x)
(-x,-y)
(x,-y)
(-x,y) (x,y)
(-y,x)
(y,x)
(-y,-x)
(y,-x)
(-x,-y)
(x,-y)
f(x,y) < 0
f(x,y) > 0
x0
E = d(x0+2,y0-1/2) - d(x0+1,y0-1/2) = 2x0+3
if d>0 we move South-East:
/* East */
/* South East */
Pseudo
Code
for
Circle
Midpoint
MidpointCircle (R)
begin
int x, y, d;
x := 0;
y :=R;
d := 1-R;
E = 3;
SE = -2R+5;
CirclePoints(x,y);
while ( y>x ) do
if ( d<0 ) then
d := d+E;
E := E+2;
SE := SE+2;
x := x+1;
end;
else
d := d+SE;
E := E+2;
SE := SE+4;
x := x+1;
y := y-1;
end;
CirclePoints( x,y );
end;
/* originally d := 5.0/4.0 - R */
/* East */
/* See Foley & van Dam pg. 87 */
/* South East */
/* See Foley & van Dam pg. 87 */
Circle Midpoint
Polygon Fill
Representation:
Polygon = V0, V1, V2, .. Vn
Vi=(xi,yi) - vertex
Ei=(vi,vi+1) - edge
En=(vn,v0)
v0
v2
E0
E6
edge
v1
v4
v6
vertex
E1
v3
v5
Solutions:
Flood fill
Scan Conversion
Fill Polygon
B
C
H
D
ymin
3 12
ymax
10
15
3 12
Scan Conversion
Very simple.
More complex
Common in paint
packages