Upload
emerald-richard
View
241
Download
3
Embed Size (px)
Citation preview
1
Transformation
2
Matrix
column and row
•
identity matrix
1st row
2nd row
3rd row
1st
column
2nd
column
3rd column
transpose
matrix composition
M-1 is an inverse matrix of M if MM-1=I.
3x3
333231
232221
131211
aaa
aaa
aaa
M
332313
322212
312111
aaa
aaa
aaa
M T
232221
131211
3231
2221
1211
bbb
bbb
aa
aa
aa
233213312232123121321131
232213212222122121221121
231213112212121121121111
babababababa
babababababa
babababababa
100
010
001
I
3x2 2x3
3
Translation
dyy
dxx
dy
dx
y
x
y
x
(x, y)
( x, y)
dx
dy dyyy
dxxx
A transformation is a function that maps a point/vector into another point/vector.
For now, we will discuss the basic 4 types of transformations: translation, scaling, rotation, and shearing.
Translation
4
Scaling
y
x
s
s
y
x
y
x
0
0
e.g.
x
y
(6,2)Scale by 1/2 along x
Scale by 2 along y
3 6
(3,4)4
Scaling is done about the origin. Scale x by sx along x-axis: x = sx·x Scale y by sy along y-axis: y = sy·y
The above example is called a uniform scaling where sx = sy. If sx sy, non-uniform scaling.
If 0 < sx (or sy) < 1, objects are moved closer to the origin. If sx or sy > 1, objects are moved farther from the origin.
e.g.
x
y
(6,4)
3 6x 2
4(3,2)
2x 2
5
Reflection Reflection or mirror matrix: a scaling matrix where (sx,sy) is either
(1,-1) or (–1,1). (If both sx and sy are –1, it’s a 180o rotation.)
y
x
y
x
10
01
y
x
y
x
10
01x
y
y
x
y
x
10
01
x
y
x
y
x
y
6
Rotation
Rotation by an angle about the origin.
The distance from P to the origin is r. Angles are measured CCW. x = r cos y = r sin x = r cos(+) = r cos cos - r sin sin = xcos - ysin y = r sin(+) = r cos sin + r sin cos = xsin + ycos For CW, you may use cos(-)=cos and sin(-)=-sin.
y
x
y
x
cossin
sincos
P(x, y)
P (x, y)
r
rr
7
Shearing
Shearing along x
y = y (unaffected)x = x + ay (in the example, a 0.5)
y
xa
y
x
10
1
Similarly, shearing along y
•
y
x
by
x
1
01
x
y
x
y
8
Homogeneous Coordinates
Observe that rotation, scaling & shearing (which are collectively called linear transformations) are done by “matrix composition” while translation is by “vector addition.” Can we treat them uniformly?
YES!! Use Homogeneous Coordinates.
Practical motivations for Homogeneous Coordinates. We can treat {rotation, scaling, shearing, etc.} & {translation} uniformly.
We can deal with projections (later!).
A point (x, y) in Cartesian Coordinates is represented as (wx, wy, w) in Homogeneous Coordinates where w can be any non-zero value.
e.g. (2 3) (2 3 1) = (4 6 2) = (5 7.5 2.5) = …... but, typically w=1.
9
Transformations in Homogeneous Coordinates
translation (x = x+dx, y = y+dy) scaling
rotation shearing (along x)
11100
10
01
1
dyy
dxx
y
x
dy
dx
y
x
11100
00
00
1
ys
xs
y
x
s
s
y
x
y
x
y
x
1100
0cossin
0sincos
1
y
x
y
x
1100
010
01
1
y
xa
y
x
Note that all transformations are done by “matrix composition” thanks to homogeneous coordinates.
Transformations which do not alter a body’s shape are called rigid-body transformations, and consist of rotations & translations.
10
Rotation about An Arbitrary Point
How to rotate about an arbitrary point p(x, y), not about the origin?
translatetranslate & rotatetranslate, rotate & back-translate
translate q by -p rotate by back-translate
p =(x,y)
q=(a,b)
q=(a,b)
p
q
p=O
q
p=O
qq q
q
3x3 3x3 3x3
11100
10
01
100
0cossin
0sincos
100
10
01
b
a
b
a
y
x
y
x
Thanks to Homogeneous Coordinates, three transformations can be combined into a single 3x3 matrix.
11
Inverse Transformation Note that the first and last translations are inverses of each other.
Such an inverse transformation is represented as an inverse matrix, but can be obtained pretty easily if its geometry is considered.
translate q by -p rotate by back-translate
p
q
p=O
q
p=O
qq q
q
inverse transformations
100
10
01
100
10
011
y
x
y
x
d
d
d
d
100
10
01
100
10
011
y
x
y
xx'=x+dx
x'+?=x?=- dx
12
100
010
01
100
010
011
aa
Inverse Transformation (cont’d)
scaling
rotation
shearing (along x) We have to restore y'(=y) into y and x'(=x+ay) into x, respectively. x'' = x' + ?y' = x' + ?y = x + ay + ?y = x. So, ?=-a
x'=xxsx
x'x?=x?=1/sx
100
01
0
001
100
00
001
y
x
y
x
s
s
s
s
100
0cossin
0sincos
100
0)cos()sin(
0)sin()cos(
100
0cossin
0sincos1
x
y
13
Associativity & Commutativity
Matrix multiplication is associative. So is transformation composition.
ABC = (AB)C = A(BC)
In contrast, matrix multiplication is not commutative in general. Neither is transformation composition.
• e.g. combination of rotation (by 90°CCW) & translation along y
• rotation first translation first
TRpp RTpp pp
14
3D Translation and Scaling
First of all, Homogeneous Coordinate for 3D (x y z) → (wx wy wz w) e.g (x y z 1)
Translation
Scaling
111000
100
010
001
dzz
dyy
dxx
z
y
x
dz
dy
dx
111000
000
000
000
zs
ys
xs
z
y
x
s
s
s
z
y
x
z
y
x
dzzz
dyyy
dxxx
zsz
ysy
xsx
z
y
x
15
3D Reflection
Reflection or mirror matrix: a scaling matrix where one scaling factor is –1 and two others are 1 or all of the three scaling factors are –1.
If two are –1, it’s a 180o rotation.
1000
0100
0010
0001
1000
0100
0010
0001
1000
0100
0010
0001
1000
0100
0010
0001
reflection wrt yz-plane
reflection wrt xz-plane
reflection wrt xy-plane
reflection wrt the origin
16
3D Rotation For 3D rotation, we need an axis of rotation. Also, by convention, positive angles are for CCW. Recall that, in 2D, x = xcos - ysin and y = xsin + ycos. We can consider (x,y) and (x,y) as points at xy-plane of 3D space.
•
Add z-axis and make z = z. Then, it’s 3D rotation about the z-axis.
y
x
y
x
z Rz(θ)
(x, y)(x, y)
(x, y, z)(x, y, z)
111000
0100
00cossin
00sincos
z
y
x
z
y
x
y
x
z
(x, y, 0)(x, y, 0)
17
zz
yxy
yxx
cossin
sincos
3D Rotation (cont’d) Rotation about x-axis
Note that the coordinate system follows the right hand rule. Let’s do cyclic permutation of the 3 axes, where the right hand rule holds.
Note that rotation about x-axis is the same as rotation about the old z-axis except the permutation .
For rotation about y-axis, do one more permutation! 3D shearing will be discussed when we deal with viewing.
111000
0cossin0
0sincos0
0001
z
y
x
z
y
x
yz
zx
xy
y' y z
yz' zx' x
xx
zyz
zyy
cossin
sincos
xyzx
18
Geometric Transformation of a Mesh
Apply transformations to every vertex. Geometry is transformed. Topology(connectivities) is not changed.
An example, Mesh A is displayed by drawing all of its edges (wireframe display). All vertices of A are rotated, scaled up and translated to make B, and
then wireframe-displayed.
A B
19
3D Rotation about An Arbitrary Axis
y
x
z
y
x
z
y
x
z
y
x
z
y
x
z
y
x
z
Step1: Translate such that the rotation axis passes
through the origin.
Step2: Rotate such that the rotation axis coincides
with a coordinate axis.
Step4: Inverse rotation. (Inverse of Step2)
Step5: Inverse translation. (Inverse of Step1)
Step3: Rotate by
by
20
3D Rotation about An Arbitrary Axis (cont’d)
Rotation axis is typically defined by 2 end points p1 and p2 (or a point p and a vector v) Move ∴ p1=(x1 y1 z1) to the origin.
Consider the unit vector u along the rotation axis.
1000
100
010
001
1
1
1
z
y
x
T
x
y
zp1(x1 y1 z1)
p2(x2 y2 z2)
p2 (x2 y2 z2)
p1 (x1 y1 z1)
x
y
z
unit vector u x
y
z
p1(x1 y1 z1)
p2(x2 y2 z2)
p2 (x2 y2 z2)
p1 (x1 y1 z1) z
x
y
)( 121212
12
zzyyxx
ppU
)( cbaU
Uu
21
Step2 (from u to uz) requires a rather complicated process, which will be discussed soon. Just suppose the rotation is denoted by R.
Step3 is simply
Step4: an inverse of the matrix computed at Step2 Step5: an inverse of the matrix computed at Step1 R() is a single 4x4 matrix.
3D Rotation about An Arbitrary Axis (cont’d)
1000
0100
00cossin
00sincos
)(
zR
TRRRTR z )()( 11
y
x
z
y
x
z
Ru
uz
22
Orthogonal Matrix Note that rotations we’ve devised are all about coordinate axes. Rotation for Step 2 is presented though orthogonal matrix.
2 rows vi & vj are orthonormal if i.e. each row is a unit vector, and ①• ② any two different rows are orthogonal.
Orthogonal matrix = a matrix with orthonormal rows.
• e.g.
1...000
:::::
0...100
0...010
0...001
nn
100
02/12/1
02/12/1
33
)(1
)(0
ji
ji
ji vv
y
x
z
y
x
z
Ru
uz
23
Orthogonal Matrix (cont’d) A matrix Q is orthogonal Q·QT = I (identity matrix)
Observations An orthogonal matrix transforms its rows into coordinate axes. QT = Q-1, i.e. for orthogonal matrices, the transpose is the inverse. It’s
great because inverse matrix computation is usually expensive. if Q is an orthogonal matrix, QT is also an orthogonal matrix.
Q-1·Q = I = QT·Q QT·(QT)T = I QT is orthogonal.
1...
0...010
0...001
......
nq
1q
2q0...100... ... ... ...
0 0 0
T1q T
2q Tnq
nxn nxn nxn nxn nx1 nx1
...
nq
1q
2q T1q
0
1
0...
0
e.g.
24
3D Orthogonal Matrix The same thing applies to 3D. Suppose that we have 3 orthonormal vectors as follows.••
We can make orthogonal matrices using the 3 orthonormal vectors. If the 3 vectors constitute a coordinate system, i.e. the cross product
of the 1st row and the 2nd row corresponds to the 3rd row following the right-hand rule, the orthogonal matrix is a rotation.
ux
uy
uz
v3
v2
v1
v1
v2
v3
v3
v1
v2
v1
v3
v2
25
3D Orthogonal Matrix (cont’d)
0
0
0
1
013
12
11
r
r
r
R
v1 ux
0
0
1
0
023
22
21
r
r
r
R
v2 uy
0
1
0
0
033
32
31
r
r
r
R
v3 uz
3D rotation in homogeneous coordinates.•
•
R transforms v1, v2 and v3 into ux, uy and uz, respectively.
1000
0
0
0
333231
232221
131211
rrr
rrr
rrr
R
v1
v2
v3 ux
uy
uz
v3
v2
v1
‘an’ orthogonal matrix
26
3D Rotation about An Arbitrary Axis (cont’d)
z
1000
0
0
0
3
2
1
u=v
v
v
u =
0
1
0
0
0
zu
u = v3
y
xxu
yu
zu
Recall that, after Step1, our goal was to rotate u into uz.
• For this purpose, let’s make a rotation matrix whose 3rd
row is u.
27
3D Rotation about An Arbitrary Axis (cont’d)
Let’s simply put R into R()=T-1R-1Rz()RT. Importantly, RT is used for R-1.
321
2
3
vvv
uu
uuv
uv
x
x
u = v3
uz
ux
uy
y
x
z v1
v2
is used to make be perpendicular to .
You can use any coordinate axis vector if it is not equal to u .
xu 2v
3v
1000
0
0
0
3
2
1
u=v
v
v
R =
28
Modeling Transformation
29
Modeling Transformation
30
Modeling Transformation
A r p B
),(),('' yxTyxScaleM xvyx
Modeling Transformation
'y
'xx
p B A r
y
x
y
31
Modeling Transformation
p B A
y
xp B A r
y
x
Translate by -r, bringing r to the origin.
p B A
y
x p B A
y
x
)(ARotate )(Atranslate
32
Modeling Transformation
translate both A and B by –p,bringing p to the origin.
p B A
y
xp B A
y
x
Rotate A&B Translate
p B A
y
x
p B
A
y
x
33
Modeling Transformation