Upload
snoopyflyingace6695
View
224
Download
0
Embed Size (px)
Citation preview
7/31/2019 Transforms (1)
1/51
Geometric Transformations
Jehee Lee
Seoul National University
7/31/2019 Transforms (1)
2/51
Transformations
Linear transformations
Rigid transformations
Affine transformations
Projective transformations
T
Global reference frame
Local moving frame
7/31/2019 Transforms (1)
3/51
Linear Transformations
A linear transformationT is a mapping betweenvector spaces
Tmaps vectors to vectors
linear combination is invariant under T
In 3-spaces, T can be represented by a 3x3 matrix
)()()()( 11000
NN
N
i
ii TcTcTccT vvvv
major)(Row
major)(Column)(
3331
1333
Nv
vMvT
7/31/2019 Transforms (1)
4/51
Examples of Linear Transformations
2D rotation
2D scaling
y
x
y
x
cossin
sincos
ysxs
yx
ss
yx
y
x
y
x
00
yx, yx ,
7/31/2019 Transforms (1)
5/51
Examples of Linear Transformations
2D shear Along X-axis
Along Y-axis
y
dyx
y
xd
y
x
10
1
dxy
x
y
x
dy
x
1
01
7/31/2019 Transforms (1)
6/51
Examples of Linear Transformations
2D reflection Along X-axis
Along Y-axis
y
x
y
x
y
x
10
01
y
x
y
x
y
x
10
01
7/31/2019 Transforms (1)
7/51
Properties of Linear Transformations
Any linear transformationbetween 3D spacescan be represented by a 3x3 matrix
Any linear transformationbetween 3D spacescan be represented as a combination of rotation,shear, and scaling
Rotationcan be represented as a combinationof scalingand shear
7/31/2019 Transforms (1)
8/51
Changing Bases
Linear transformations as a change of bases
yx, yx ,
0v
1v1v
0v
y
x
y
x
yxyx
1010
1010
vvvv
vvvv
7/31/2019 Transforms (1)
9/51
Changing Bases
Linear transformations as a change of bases yx, yx ,
0
v
1v1v
0v
11001
11000
vvv
vvv
bb
aa
y
xT
y
x
ba
ba
y
x
y
x
ba
ba
y
x
11
00
11
00
1010 vvvv
7/31/2019 Transforms (1)
10/51
Affine Transformations
An affine transformationT is an mappingbetween affine spaces
Tmaps vectors to vectors, and points to points
T is a linear transformation on vectors
affine combination is invariant under T
In 3-spaces, T can be represented by a 3x3matrix together with a 3x1 translation vector
)()()()( 11000
NN
N
i
ii TcTcTccT pppp
131333)( TpMpT
7/31/2019 Transforms (1)
11/51
Homogeneous Coordinates
Any affine transformation between 3D spacescan be represented by a 4x4 matrix
Affine transformation is linear in homogeneouscoordinates
110)(
131333 pTMpT
7/31/2019 Transforms (1)
12/51
Examples of Affine Transformations
2D rotation
2D scaling
1100
0cossin
0sincos
1
y
x
y
x
yx, yx ,
11100
00
00
1
ys
xs
y
x
s
s
y
x
y
x
y
x
7/31/2019 Transforms (1)
13/51
Examples of Affine Transformations
2D shear
2D reflection
11100
010
01
1
y
dyx
y
xd
y
x
11100
010001
1
yx
yx
yx
7/31/2019 Transforms (1)
14/51
Examples of Affine Transformations
2D translation
11100
10
01
1y
x
y
x
ty
tx
y
x
t
t
y
x
7/31/2019 Transforms (1)
15/51
Examples of Affine Transformations
2D transformation for vectors Translationis simply ignored
00100
1001
0
yx
yx
tt
yx
y
x
7/31/2019 Transforms (1)
16/51
Examples of Affine Transformations
3D rotation
11000
0cossin0
0sincos0
0001
1
z
y
x
z
y
x
11000
0100
00cossin
00sincos
1
z
y
x
z
y
x
11000
0cos0sin
0010
0sin0cos
1
z
y
x
z
y
x
7/31/2019 Transforms (1)
17/51
Composite Transformations
Composite 2D Translation
),(
),(),(
2121
2211
yyxx
yxyx
tttt
ttttT
T
TT
100
10
01
100
10
01
100
10
01
21
21
1
1
2
2
yy
xx
y
x
y
x
tt
tt
t
t
t
t
7/31/2019 Transforms (1)
18/51
Composite Transformations
Composite 2D Scaling
),(
),(),(
2121
2211
yyxx
yxyx
ssss
ssssT
S
SS
100
00
00
100
00
00
100
00
00
21
21
1
1
2
2
yy
xx
y
x
y
x
ss
ss
s
s
s
s
7/31/2019 Transforms (1)
19/51
Composite Transformations
Composite 2D Rotation
)(
)()(
12
12
R
RRT
100
0)cos()sin(
0)sin()cos(
100
0cossin
0sincos
100
0cossin
0sincos
1212
1212
11
11
22
22
7/31/2019 Transforms (1)
20/51
Composing Transformations
Suppose we want,
We have to compose two transformations
)90( R )3,(xT
7/31/2019 Transforms (1)
21/51
Composing Transformations
Matrix multiplication is not commutative
)3,()90()90()3,( xx TRRT
Translationfollowed by
rotation
Translationfollowed by
rotation
7/31/2019 Transforms (1)
22/51
Composing Transformations
R-to-L : interpret operations w.r.t. fixed coordinates
L-to-R : interpret operations w.r.t local coordinates
)90()3,( RT xT
)90(R
)3,(xT
)90( R)3,(xT
(Column major convention)
7/31/2019 Transforms (1)
23/51
Pivot-Point Rotation
Rotation with respect to a pivot point (x,y)
100
sin)cos1(cossin
sin)cos1(sincos100
10
01
100
0cossin
0sincos
100
10
01
),()(),(
xy
yx
y
x
y
x
yxTRyxT
7/31/2019 Transforms (1)
24/51
Fixed-Point Scaling
Scaling with respect to a fixed point (x,y)
100
)1(0
)1(0
100
10
01
100
00
00
100
10
01
),(),(),(
yss
xss
y
x
s
s
y
x
yxTssSyxT
yy
xx
y
x
yx
7/31/2019 Transforms (1)
25/51
Scaling Direction
Scaling along an arbitrary axis
)(),()(1 RssSR yx
)(1 R),( yx ssS)(R
7/31/2019 Transforms (1)
26/51
Properties of Affine Transformations
Any affine transformationbetween 3D spaces can berepresented as a combination of a linear transformationfollowed by translation
An affine transf. maps linesto lines
An affine transf. maps parallel linesto parallel lines
An affine transf. preserves ratios of distancealong a line
An affine transf. does not preserve absolute distancesand angles
7/31/2019 Transforms (1)
27/51
Review of Affine Frames
A frameis defined as a set of vectors {vi | i=1, , N}and a point o
Set of vectors {vi} are bases of the associate vectorspace
o is an origin of the frame N is the dimension of the affine space
Any point p can be written as
Any vector v can be written as
NNccc vvvop 2211
NNccc vvvv 2211
7/31/2019 Transforms (1)
28/51
Changing Frames
Affine transformations as a change of frame
yx,
0v
1v
11
1010
1010
y
x
y
x
yxyx
ovvovv
ovvovv
0v1v
o
o
7/31/2019 Transforms (1)
29/51
Changing Frames
Affine transformations as a change of frame
ovvo
vvv
vvv
100
11001
11000
cc
bb
aa
11001
11001
111
000
111
000
1010
y
x
cba
cba
y
x
y
x
cba
cba
y
x
ovvovv
yx,
0v
1v0v
1v
o
o
7/31/2019 Transforms (1)
30/51
Changing Frames
In case the xyz system has standard bases
7/31/2019 Transforms (1)
31/51
Rigid Transformations
A rigid transformationT is a mapping betweenaffine spaces
Tmaps vectors to vectors, and points to points
Tpreserves distances between all points
Tpreserves cross product for all vectors (to avoidreflection)
In 3-spaces, T can be represented as
1detand
where,)( 131333
RIRRRR
TpRp
TT
T
7/31/2019 Transforms (1)
32/51
Rigid Body Rotation
Rigid body transformations allow only rotationand translation
Rotation matrices form SO(3)
Special orthogonal group
IRRRR TT
1det R
(Distance preserving)
(No reflection)
7/31/2019 Transforms (1)
33/51
Rigid Body Rotation
R is normalized The squares of the elements in any row or column
sum to 1
R is orthogonal The dot product of any pair of rows or any pair
columns is 0
The rows (columns) of R correspond to thevectors of the principle axes of the rotatedcoordinate frame
IRRRR TT
7/31/2019 Transforms (1)
34/51
3D Rotation About Arbitrary Axis
7/31/2019 Transforms (1)
35/51
3D Rotation About Arbitrary Axis
1. Translation : rotation axis passes through theorigin
2. Make the rotation axis on the z-axis
3. Do rotation
4. Rotation & translation
),,( 111 zyxT
)()( yx RR
)(zR
)()(111
xy RRT
7/31/2019 Transforms (1)
36/51
3D Rotation About Arbitrary Axis
Rotate u onto the z-axis
7/31/2019 Transforms (1)
37/51
3D Rotation About Arbitrary Axis
Rotate u onto the z-axis
u: Project u onto the yz-plane to compute angle
u: Rotate u about the x-axis by angle
Rotate u onto the z-axis
7/31/2019 Transforms (1)
38/51
3D Rotation About Arbitrary Axis
Rotate u about the x-axis onto the z-axis Let u=(a,b,c) and thus u=(0,b,c)
Let uz=(0,0,1)
22cos
cbc
z
z
uu
uu
bx
zxz
u
uuuuu sin22
sincb
bb
z
uu
7/31/2019 Transforms (1)
39/51
3D Rotation About Arbitrary Axis
Rotate u about the x-axis onto the z-axis Since we know both cos and sin , the rotation
matrix can be obtained
Or, we can compute the signed angle
Do not use acos() since its domain is limited to [-1,1]
1000
00
00
0001
)(
2222
2222
cb
c
cb
b cb
b
cb
c
x R
),(atan22222 cb
b
cb
c
7/31/2019 Transforms (1)
40/51
Euler angles
Arbitrary orientation can be represented by threerotation along x,y,z axis
1000
0
00CS-SSCCC
)()()(),,(
CCSCS
SCCSSCCSSSCSSSCSC
RRRR xyzXYZ
7/31/2019 Transforms (1)
41/51
Gimble
Hardware implementation of Euler angles Aircraft, Camera
7/31/2019 Transforms (1)
42/51
Euler Angles
Rotation about threeorthogonal axes 12 combinations
XYZ, XYX, XZY, XZX
YZX, YZY, YXZ, YXY
ZXY, ZXZ, ZYX, ZYZ
Gimble lock
Coincidence of inner mostand outmost gimbles rotation
axes Loss of degree of freedom
7/31/2019 Transforms (1)
43/51
Euler Angles
Euler angles are ambiguous Two different Euler angles can represent the same
orientation
This ambiguity brings unexpected results of animationwhere frames are generated by interpolation.
),2
,0and)0,2
,21
(R(),r,r(rRzyx
7/31/2019 Transforms (1)
44/51
Taxonomy of Transformations
Linear transformations 3x3 matrix
Rotation + scaling + shear
Rigid transformations
SO(3) for rotation 3D vector for translation
Affine transformation 3x3 matrix + 3D vector or 4x4 homogenous matrix
Linear transformation + translation
Projective transformation 4x4 matrix
Affine transformation + perspective projection
7/31/2019 Transforms (1)
45/51
Taxonomy of Transformations
Projective
Affine
Rigid
7/31/2019 Transforms (1)
46/51
Composition of Transforms
What is the composition of linear/affine/rigidtransformations ?
What is the linear (or affine) combination oflinear (or affine) transformations ?
What is the linear (or affine) combination of rigid
transformations ?
7/31/2019 Transforms (1)
47/51
OpenGL Geometric Transformations
glMatrixMode(GL_MODELVIEW);
7/31/2019 Transforms (1)
48/51
OpenGL Geometric Transformations
Construction glLoadIdentity();
glTranslatef(tx, ty, tz);
glRotatef(theta, vx, vy, vz);
(vx, vy, vz)is automatically normalized
glScalef(sx, sy, sz);
glLoadMatrixf(Glfloat elems[16]);
Multiplication glMultMatrixf(Glfloat elems[16]);
The current matrix is postmultiplied by the matrix
Row major
7/31/2019 Transforms (1)
49/51
Hierarchical Modeling
A hierarchical model is created by nesting thedescriptions of subparts into one another to form a treeorganization
7/31/2019 Transforms (1)
50/51
OpenGL Matrix Stacks
Four matrix modes Modelview, projection, texture, and color
glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH,
stackSize);
Stack processing
The top of the stack is the current matrix
glPushMatrix(); // Duplicate the current matrix at the top glPopMatrix(); // Remove the matrix at the top
7/31/2019 Transforms (1)
51/51
Programming Assignment #1
Create a hierarchical model using matrix stacks
The model should consists of three-dimensionalprimitives such as polygons, boxes, cylinders,spheres and quadrics.
The model should have a hierarchy of at leastthree levels
Animate the model to show the hierarchicalstructure
Eg) a car driving with rotating wheels Eg) a runner with arms and legs swing
Make it aesthetically pleasing or technicallyillustrative