Professional Documents
Culture Documents
2M050: Computer Graphics: Jack Van Wijk Vanwijk@win - Tue.nl HG6.71
2M050: Computer Graphics: Jack Van Wijk Vanwijk@win - Tue.nl HG6.71
2
Literature
3
Overview
Introduction
Geometry
Interaction
Raster graphics
4
Introduction
5
Computer Graphics
6
Computer Graphics
Image Analysis
(pattern recognition)
Mathematical
Image
Model
Image Synthesis
(Rendering)
8
Applications
10
Interactive Computer Graphics
User input
Application
Screen image
11
Graphics pipeline
User Edit
Model
Map
Geometry, colour
Screen Display
12
Representations in graphics
Vector Graphics
• Image is represented by continuous
geometric objects: lines, curves, etc.
Raster Graphics
• Image is represented as an rectangular grid
of coloured squares
13
Vector graphics
14
Raster graphics
• Generic
• Image processing techniques
• Geometric Transformation: loss of information
• Complexity ~ O(number of pixels)
• Jagged edges, anti-aliasing
• Realistic images, textures, ...
• Examples: Paint, PhotoShop, ...
15
Conversion
Vector graphics
Raster graphics
16
Hardware
• Vector graphics
• Raster graphics
• Colour lookup table
• 3D rendering hardware
17
Vector Graphics Hardware
Display list
continuous & smooth move 10 20
lines
no filled objects line 20 40
random scan
...
refresh speed depends
on complexity of the
char O
scene
VECTOR
char R
Display Controller 18
Raster Graphics Hardware
Frame buffer
0 0 0 0 0 0
0 7 7 7 6
0 7 7 7 Video Controller
0 0 0 RASTER
0 0
0
jaggies (stair casing) refresh speed independent of scan conversion
scene complexity
filled objects resolution
pixel
(anti)aliasing bit planes 19
Colour Lookup Table
colour R G B
Frame buffer index
0 0 0 0
0 0 0 0 0 0
0 7 7 7 6 1 CLUT:
102 255 53
0 7 7 7 pixel = code
2 255 255 204
0 0 0
0 0 4 255 102 153 True colour:
0 ...
pixel = R,G,B
7 102 0 51
20
3D rendering hardware
• Coordinates
• Transformations
• Parametric and implicit representations
• Algorithms
22
Coordinates
x = (x, y) v
x
x = (x1 , x2)
x = x1 e1 + x2 e2, e1 = (1, 0), e2 = (0, 1)
• Vector: direction and magnitude
v = (vx , vy), etc.
23
Vector arithmetic
v x
• Multiplication vector-scalar: y
2v
v = (vx , vy)
v
x
24
Coordinate systems
world
train
wheel
image
25
Why transformations?
• Model of objects
world coordinates: km, mm, etc.
hierarchical models:
human = torso + arm + arm + head + leg + leg
arm = upperarm + lowerarm + hand …
• Viewing
zoom in, move drawing, etc.
26
Transformation types
27
Homogeneous coordinates
28
Homogeneous coordinates
29
Matrices for transformation
x' Mx , or
x' m11 m12 m13 x
y ' m21 m22 m23 y , or
w' m m m w
31 32 33
x' m11 x m12 y m13 w
y ' m21 x m22 y m23 w
w' m31 x m32 y m33 w
30
Direct interpretation
y’
x' M x, or (x, y )
y
x' a b t x, or (x’,y’)
x
x' a x bx t x x b
a
y ' a y by t y y
1 0 0 1 1 t
x’
31
Translation matrix
Translation :
x' T (t x , t y )x , with
1 0 tx
T (t x , t y ) 0 1 t y
0 0 1
32
Scaling matrix
Scaling :
x' S( s x , s y )x , with
sx 0 0
S( s x , s y ) 0 sy 0
0 0 1
33
Rotation matrix
Rotation :
x' R( ) x , with
cos sin 0
R( ) sin cos 0
0 0 1
34
Sequences of transformations
x’’’
y’’’ x' R ( / 2)x
y x' ' S(1/2)x'
x’
x' ' ' T(5,4) x' '
y’ or
x’’
x' ' ' Mx, with
y’’
M T(5,4)S(1/2)R( / 2)
x
Sequences of transformations can be described with a single
transformation matrix, which is the result of concatenation of
all transformations. 35
Order of transformations
y’
y’’ y’’
x’’ x’’
’ y y
y
x’
x’
x x
x' ' T(2,3)R(30)x x' ' R(30)T(2,3) x
Matrix multiplication is not commutative. Different
orders of multiplication give different results. 36
Order of transformations
• Pre-multiplication:
x’ = M n M n-1…M 2 M 1 x
Transformation M n in global coordinates
• Post-multiplication:
x’ = M 1 M 2…M n-1 M n x
Transformation M n in local coordinates, i.e., the
coordinate system that results from application of
M 1 M 2…M n-1
37
Window and viewport
Viewport: (800,600)
(600,400)
Area on screen to be used for drawing.
Unit: pixels (screen coordinates)
(200,200)
Note: y-axis often points down
(0,0)
(2,1)
Window:
Virtual area to be used by application
Unit: km, mm,… (world coordinates)
(-2,-1) 38
Window/viewport transform
(vx2, vy2)
Viewport
Drawing: (meters to pixels)
x’:screen coordinates
(vx1, vy1) Use x’ = Mx
Drawing Picking
Picking:(pixels to meters)
Window: (wx2, wy2)
Use x = M-1x’
x: user coordinates
(wx1, wy1)
40
Implementation example
41
State variables
42
Procedures
43
Procedures (continued)
44
Procedures (continued)
• Drawing procedures:
MyMoveTo(x, y):
(x’, y’) = Mwv*Mobject*(x,y);
MoveTo(x’, y’)
MyLineTo(x,y):
(x’, y’) = Mwv*Mobject*(x,y);
LineTo(x’, y’)
46
Application
47
Puzzles
48
Geometry
49
Good and bad
50
Dot product
51
Dot product properties
vw w v
( v w) u v u w u
( v ) w v w
v v | v |2
v w 0 iff v and w are perpendicular
52
Determinant
Det ( v, w ) v x wy v y wx
| v | | w | sin w
is angle from v to w v
0 : Det ( v, w ) 0 v
2 : Det ( v, w ) 0
w
Det(v, w): signed area of parallellogram
Det(v, w) = 0 iff v and w are parallel
53
Curve representations
• Implicit: f(x) = 0
54
Parametric line representation
55
Parametric representation
56
Implicit line representation
• (x-p).n = 0
with n.v = 0
y
n is normal vector:
n = [-vy , vx]
n p
• Also:
ax+by+c=0 v x
57
Implicit representation
f (x) 0 : curve
f=1
f (x) C : contours f >0
f=0
f 0 divides plane in
f =-1
two areas : f 0 and f 0
f =-2
| f (x) | : measure of distance
f <0
of x to curve
58
Circle
Parametric :
( x, y ) (r cos , r sin ) y
Implicit : r x
x y r 0
2 2 2
59
Ellipse
Parametric :
( x, y ) (a cos , b sin )
y
Implicit : b a x
2 2
x y
1 0
a b
60
Generic ellipse
Parametric : a
y b
x( ) c a cos b sin c
x
Implicit :
| Mx | 1, with M a b c
1
61
Some standard puzzles
62
Conversion line representations
Given line :
p ( s ) a us;
Find implicit representation :
n x c 0.
First, determine normal n. s
65
Solving for s and t
p( s ) q(t ), or
a us b vt , or
s
u v b a, or
t s
s t
u v (b a), or
1
a u v
t b
s 1 vy v x bx a x
u u x by a y
t u x v y u y vx y
66
Position points/line
67
Line/circle intersection
Find intersections of :
line : p(t ) a ut , 0 t 1 and
circle : x x r 2 .
y
At intersection :
u
p(t ) p(t ) r , or
2
r x
(a ut ) (a ut ) r 2 , or
t
u u t 2 a u t a a r 2 0.
a
Solve quadratic equation for t :
0, 1, or 2 solutions.
68
Polygons
pN pi
p2
p1
69
Regular N-gon
p i (r cos i , r sin i )
i 2 (i 1 / 2) / N / 2
70
Convex and concave
• Convex:
– each line between two
arbitrary points inside
the polygon does not
cross its boundary
• Concave:
– not convex
71
Convexity test
pi pi
pi-1 pi-1
Convex Concave
72
Polygon area and orientation
N
a Det (p i c, p i 1 c) / 2, c is arbitrary point
i
area | a |
a 0 : counterclockwise orientation
a 0 : clockwise orientation pi+1
c
pi
73
Point/polygon test
2
Solution :
1
Define a line L c vt , t 0. 3
v can be chosen arbitrarily, f.i. (1, 0).
Let n be the number of crossings of L
with the polygon. If n is odd : point is
inside, else it is outside.
74
Point/polygon test (cntd.)
75
Puzzles
76