Академический Документы
Профессиональный Документы
Культура Документы
(Chapter 5 in FVD)
2D Geometric
Transformations
• Question: How do we represent a
geometric object in the plane?
• Answer: For now, assume that
objects consist of points and lines.
A point is represented by its
Cartesian coordinates: (x,y).
Translate(2,4)
Scale
• Scale (a,b): (x,y) (ax,by)
Scale (2,3)
Scale (2,3)
4
• How can we scale an object
without moving its origin (lower
left corner)?
Translate(-1,-1)
Translate(1,1) Scale(2,3)
Reflection
Scale(-1,1)
Scale(1,-1)
6
Rotation
• Rotate(θ):
(x,y) (x cos(θ)+y sin(θ), -x sin(θ)+y cos(θ))
Rotate(90)
Rotate(90)
Translate(-1,-1)
Translate(1,1)
Rotate(90)
8
Shear
• Shear (a,b): (x,y) (x+ay,y+bx)
Shear(1,0)
Shear(0,2)
Composition of
Transformations
• Rigid transformation:
– Translation + Rotation (distance
preserving).
• Similarity transformation:
– Translation + Rotation + uniform
Scale (angle preserving).
• Affine transformation:
– Translation + Rotation + Scale +
Shear (parallelism preserving).
• All above transformations are groups
where Rigid ⊂ Similarity ⊂ Affine.
10
Matrix Notation
• Let’s treat a point (x,y) as a 2x1
matrix (a column vector):
x
y
a b x ax + by
c d y = cx + dy
11
2D Transformations
x ' a b x
' = d
12
Scale
• Scale(a,b): (x,y) (ax,by)
a 0 x ax
0 b y = by
13
Reflection
• Reflection through the y axis:
− 1 0
0 1
• Reflection through the x axis:
1 0
0 −1
• Reflection through y=x:
0 1
1 0
• Reflection through y=-x:
0 − 1
− 1 0
14
Shear, Rotation
1 a x x + ay
b 1 y = y + bx
• Rotate(θ):
(x,y) (xcosθ+ysinθ , -xsinθ + ycosθ)
15
Composition of Transformations
• A sequence of transformations
can be collapsed into a single
matrix:
[A][B ][C ]
x x
= [D ] y
y
• Note: order of transformations is
important! (otherwise - commutative groups)
translate rotate
rotate translate
16
Translation
x x + a
• Translation(a,b): →
y y + b
• Problem: Cannot represent
translation using 2x2 matrices.
• Solution:
Homogeneous Coordinates
17
Homogeneous Coordinates
• Homogeneous Coordinates is a
mapping from Rn to Rn+1:
• Inverse mapping:
X Y
( X , Y ,W ) → ,
W W
18
Translation
• Translate(a,b):
1 0 a x x + a
0 1 b y = y + b
0 0 1 1 1
a b e
c d f
0 0 1
19
Geometric Interpretation
W
Y
(X,Y,W)
1 y
x
(X,Y,1)
X
• A 2D point is mapped to a line
(ray) in 3D. The non-homogeneous
points are obtained by projecting
the rays onto the plane Z=1.
20
• Example: Rotation about an
arbitrary point:
(x0,y0)
• Actions:
– Translate the coordinates so that the
origin is at (x0,y0).
– Rotate by θ.
– Translate back.
1 0 x0 cosθ − sin θ 0 1 0 − x0 x
0 1 y sin 0 0 1 − y0 y =
0 θ cosθ
0 0 1 0 0 1 0 0 1 1
p2
p1
L=p1+t (p2-p1)=t p2+(1-t) p1
• Actions:
– Translate the coordinates so that P1
is at the origin.
– Rotate so that L aligns with the x-
axis.
– Reflect about the x-axis.
– Rotate back.
– Translate back.
22
Viewing in 2D
(Chapter 6 in FVD)
World Coordinate
Device Coordinate Window
Viewport
Object in World
g
pin
map
:2D
3D
2D:2D mapping
23
Viewing in 2D (cont.)
Maximum range
of screen
Window coordinates
Viewport
Window to Viewport
Transformation
24
Window to Viewport Transformation
(xmax,ymax) (umax,vmax)
(xmin,ymin) (umin,vmin)
u -u v -v
Mwv = T(umin,vmin) S( xmax -xmin , ymax -ymin ) T(-xmin,-ymin)
max min max min
umax-umin
1 0 umin xmax-xmin v 0-v 0 1 0 -xmin
max min
= 0 1 vmin 0 ymax-ymin 0 0 1 -ymin
0 0 1 0 0 1 0 0 1
umax-umin umax-umin
xmax-xmin 0 xmax-xmin (-xmin) + umin
= vmax-vmin vmax-vmin
0 ymax-ymin y -y (-ymin) + vmin
max min
0 0 1
25