2D Geometric Transformations - BIUu.cs.biu.ac.il/~kapaho/CG/04_2d_trans.pdf · 2D Geometric...
Transcript of 2D Geometric Transformations - BIUu.cs.biu.ac.il/~kapaho/CG/04_2d_trans.pdf · 2D Geometric...
1
2D Geometric Transformations
(Chapter 5 in FVD)
2
2D geometric transformation
• Translation
• Scaling
• Rotation
• Shear
• Matrix notation
• Compositions
• Homogeneous coordinates
3
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).
• Question: How do we transform a
geometric object in the plane?
• Answer: Let (A,B) be a straight line
segment and T a general 2D
transformation: T transforms (A,B)
into another straight line segment
(A’,B’), where A’=TA and B’=TB.
4
Translation
• Translate (a,b): (x,y) (x+a,y+b)
Translate(2,4)
5
Scale
• Scale (a,b): (x,y) (ax,by)
Scale (2,3)
Scale (2,3)
6
• How can we scale an object
without moving its origin (lower
left corner)?
Translate(-1,-1)
Translate(1,1) Scale(2,3)
7
Reflection
Scale(-1,1)
Scale(1,-1)
8
Rotation
• Rotate(q):
(x,y) (x cos(q)+y sin(q), -x sin(q)+y cos(q))
Rotate(90)
Rotate(90)
9
• How can we rotate an object
without moving its origin (lower
left corner)?
Translate(-1,-1)
Translate(1,1)
Rotate(90)
10
Shear
• Shear (a,b): (x,y) (x+ay,y+bx)
Shear(1,0)
Shear(0,2)
11
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.
12
Rigid
Affine
Similarity
13
Matrix Notation
• Let’s treat a point (x,y) as a 2x1
matrix (a column vector):
• What happens when this vector is
multiplied by a 2x2 matrix?
y
x
dycx
byax
y
x
dc
ba
14
2D Transformations
• 2D object is represented by points
and lines that join them.
• Transformations can be applied
only to the the points defining the
lines.
• A point (x,y) is represented by a
2x1 column vector, and we can
represent 2D transformations
using 2x2 matrices:
y
x
dc
ba
y
x
'
'
15
Scale
• Scale(a,b): (x,y) (ax,by)
• If a or b are negative, we get
reflection.
• Inverse: S-1(a,b)=S(1/a,1/b)
by
ax
y
x
b
a
0
0
16
Reflection
• Reflection through the y axis:
• Reflection through the x axis:
• Reflection through y=x:
• Reflection through y=-x:
10
01
10
01
01
10
01
10
17
Shear, Rotation
• Shear(a,b): (x,y) (x+ay,y+bx)
• Rotate(q):
(x,y) (xcosq+ysinq , -xsinq + ycosq)
• Inverse: R-1(q)=RT(q)=R(-q)
bxy
ayx
y
x
b
a
1
1
cossin
sincos
cossin
sincos
yx
yx
y
x
18
Composition of Transformations
• A sequence of transformations
can be collapsed into a single
matrix:
• Note: order of transformations is
important! (otherwise - commutative groups)
y
xD
y
xCBA
translate rotate
rotate translate
19
Composition of Transformations
(Cont.)
D = A B C
D-1 = C-1B-1A-1
D * D-1 = ABC * C-1B-1A-1 =
AB*I*B-1*A-1=
A*I*A = I
Proof:
20
Translation
• Translation(a,b):
• Problem: Cannot represent
translation using 2x2 matrices.
• Solution:
Homogeneous Coordinates
by
ax
y
x
21
Homogeneous Coordinates
• Homogeneous Coordinates is a
mapping from Rn to Rn+1:
• Note: (tx,ty,t) all correspond to
the same non-homogeneous point
(x,y). E.g. (2,3,1)(6,9,3).
• Inverse mapping:
),,(),,(),( ttytxWYXyx
W
Y
W
XWYX ,),,(
22
Translation
• Translate(a,b):
• Inverse: T-1(a,b)=T(-a,-b)
• Affine transformation now have
the following form:
11100
10
01
by
ax
y
x
b
a
100
fdc
eba
23
(X,Y,W)
y
x
X
Y
W
1
(X,Y,1)
Geometric Interpretation
• 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.
24
• Example: Rotation about an
arbitrary point:
• Actions:
– Translate the coordinates so that the
origin is at (x0,y0).
– Rotate by q.
– Translate back.
(x0,y0)
q
1100
sin)cos1(cossin
sin)cos1(sincos
1100
10
01
100
0cossin
0sincos
100
10
01
00
00
0
0
0
0
y
x
xy
yx
y
x
y
x
y
x
qqqq
qqqq
25
• Another example: Reflection
about an Arbitrary Line:
• 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.
p1
p2
L=p1+t (p2-p1)=t p2+(1-t) p1
26
Change of Coordinates
• It is often requires the transformation of
object description from one coordinate
system to another.
• How do we transform between two
Cartesian coordinate systems?
• Rule: Transform one coordinate frames
towards the other in the opposite
direction of the representation change.
x
y
x’y’
27
Change of Coordinates (Cont.)
X
Y
P’
O
P
X’
Y’O’
Example:
28
• Example:
– Represent the point P=(xp,yp,1) in the
(x’,y’) coordinate system.
x
y x’y’
q
(x0,y0)(xp,yp)
MPP '
100
10
01
100
0cossin
0sincos
0
0
11 y
x
TRM qq
where
29
• Alternative method:
– Assume x’=(ux,uy) and y’=(vx,vy) in the
(x,y) coordinate system .
x
yx’y’
(x0,y0)
MPP '
100
10
01
100
0
0
0
0
y
x
vv
uu
M yx
yx
where
(ux,uy)(vx,vy)
30
• Example:
– P is at the y’ axis P=(vx,vy):
– What is the inverse?
x
y
x’y’
(ux,uy)
(vx,vy)
110
1100
0
0
' y
x
yx
yx
v
v
vv
uu
MPP
31
• Another example: Reflection about an
Arbitrary Line:
• Define a coordinate systems (u,v)
parallel to P1P2:
p1
p2
x
y
y
x
u
u
pp
pp
12
12u
y
x
x
y
v
v
u
uv
100
10
01
100
0
0
100010001
100
0
0
100
10
01
1
1
1
1
y
x
y
x
p
p
vv
uu
vu
vu
p
p
M yx
yx
yy
xx