Вы находитесь на странице: 1из 51

Geometric Transformations

Jehee Lee
Seoul National University
Transformations
Linear transformations

Rigid transformations

Affine transformations

Projective transformations
T
Global reference frame
Local moving frame
Linear Transformations
A linear transformation T is a mapping between
vector spaces
T maps vectors to vectors
linear combination is invariant under T



In 3-spaces, T can be represented by a 3x3 matrix
) ( ) ( ) ( ) (
1 1 0 0
0
N N
N
i
i i
T c T c T c c T v v v v + + + =

=

major) (Row
major) (Column ) (
3 3 3 1
1 3 3 3


=
=
N v
v M v T
Examples of Linear Transformations
2D rotation




2D scaling
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
u u
u u
cos sin
sin cos
|
|
.
|

\
|
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
y s
x s
y
x
s
s
y
x
y
x
y
x
0
0
( ) y x,
( ) y x
' '
,
Examples of Linear Transformations
2D shear
Along X-axis




Along Y-axis
|
|
.
|

\
|
+
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
y
dy x
y
x d
y
x
1 0
1
|
|
.
|

\
|
+
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
dx y
x
y
x
d y
x
1
0 1
Examples of Linear Transformations
2D reflection
Along X-axis





Along Y-axis
|
|
.
|

\
|

=
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
y
x
1 0
0 1
|
|
.
|

\
|

=
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
y
x
1 0
0 1
Properties of Linear Transformations
Any linear transformation between 3D spaces
can be represented by a 3x3 matrix

Any linear transformation between 3D spaces
can be represented as a combination of rotation,
shear, and scaling

Rotation can be represented as a combination
of scaling and shear
Changing Bases
Linear transformations as a change of bases
( ) y x,
( ) y x
' '
,
0
v
1
v
'
1
v
0
v
'
( ) ( )
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
' '
+ =
' '
+
' '
y
x
y
x
y x y x
1 0 1 0
1 0 1 0
v v v v
v v v v
Changing Bases
Linear transformations as a change of bases
( ) y x,
( ) y x
' '
,
0
v
1
v
'
1
v
0
v
'
1 1 0 0 1
1 1 0 0 0
v v v
v v v
'
+
'
=
'
+
'
=
b b
a a
( ) ( )
|
|
.
|

\
|
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
|
|
.
|

\
|
|
|
.
|

\
|
' '
=
|
|
.
|

\
|
'
'
' '
y
x
T
y
x
b a
b a
y
x
y
x
b a
b a
y
x
1 1
0 0
1 1
0 0
1 0 1 0
v v v v
Affine Transformations
An affine transformation T is an mapping
between affine spaces
T maps 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 3x3
matrix together with a 3x1 translation vector

) ( ) ( ) ( ) (
1 1 0 0
0
N N
N
i
i i
T c T c T c c T p p p p + + + =

=

1 3 1 3 3 3
) (

+ = T p M p T
Homogeneous Coordinates
Any affine transformation between 3D spaces
can be represented by a 4x4 matrix



Affine transformation is linear in homogeneous
coordinates
|
|
.
|

\
|
|
|
.
|

\
|
=

1 1 0
) (
1 3 1 3 3 3
p T M
p T
Examples of Affine Transformations
2D rotation




2D scaling
|
|
|
.
|

\
|
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|
'
'
1 1 0 0
0 cos sin
0 sin cos
1
y
x
y
x
u u
u u
( ) y x,
( ) y x
' '
,
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1 1 0 0
0 0
0 0
1
y s
x s
y
x
s
s
y
x
y
x
y
x
Examples of Affine Transformations
2D shear




2D reflection
|
|
|
.
|

\
|
+
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1 1 0 0
0 1 0
0 1
1
y
dy x
y
x d
y
x
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1 1 0 0
0 1 0
0 0 1
1
y
x
y
x
y
x
Examples of Affine Transformations
2D translation

|
|
|
.
|

\
|
+
+
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1 1 0 0
1 0
0 1
1
y
x
y
x
t y
t x
y
x
t
t
y
x
Examples of Affine Transformations
2D transformation for vectors
Translation is simply ignored
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
0 0 1 0 0
1 0
0 1
0
y
x
y
x
t
t
y
x
y
x
Examples of Affine Transformations
3D rotation
|
|
|
|
|
.
|

\
|
|
|
|
|
|
.
|

\
|

=
|
|
|
|
|
.
|

\
|
'
'
'
1 1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
1
z
y
x
z
y
x
u u
u u
|
|
|
|
|
.
|

\
|
|
|
|
|
|
.
|

\
|

=
|
|
|
|
|
.
|

\
|
'
'
'
1 1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
1
z
y
x
z
y
x
u u
u u
|
|
|
|
|
.
|

\
|
|
|
|
|
|
.
|

\
|

=
|
|
|
|
|
.
|

\
|
'
'
'
1 1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
1
z
y
x
z
y
x
u u
u u
Composite Transformations
Composite 2D Translation
) , (
) , ( ) , (
2 1 2 1
2 2 1 1
y y x x
y x y x
t t t t
t t t t T
+ + =
=
T
T T
|
|
|
.
|

\
|
+
+
=
|
|
|
.
|

\
|

|
|
|
.
|

\
|
1 0 0
1 0
0 1
1 0 0
1 0
0 1
1 0 0
1 0
0 1
2 1
2 1
1
1
2
2
y y
x x
y
x
y
x
t t
t t
t
t
t
t
Composite Transformations
Composite 2D Scaling

) , (
) , ( ) , (
2 1 2 1
2 2 1 1
y y x x
y x y x
s s s s
s s s s T
S
S S
=
=
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|

|
|
|
.
|

\
|
1 0 0
0 0
0 0
1 0 0
0 0
0 0
1 0 0
0 0
0 0
2 1
2 1
1
1
2
2
y y
x x
y
x
y
x
s s
s s
s
s
s
s
Composite Transformations
Composite 2D Rotation

) (
) ( ) (
1 2
1 2
u u
u u
+ =
=
R
R R T
|
|
|
.
|

\
|
+ +
+ +
=
|
|
|
.
|

\
|

|
|
|
.
|

\
|

1 0 0
0 ) cos( ) sin(
0 ) sin( ) cos(
1 0 0
0 cos sin
0 sin cos
1 0 0
0 cos sin
0 sin cos
1 2 1 2
1 2 1 2
1 1
1 1
2 2
2 2
u u u u
u u u u
u u
u u
u u
u u
Composing Transformations
Suppose we want,




We have to compose two transformations
) 90 ( R ) 3 , (x T
Composing Transformations
Matrix multiplication is not commutative
) 3 , ( ) 90 ( ) 90 ( ) 3 , ( x x T R R T =
Translation
followed by
rotation
Translation
followed by
rotation
Composing Transformations


R-to-L : interpret operations w.r.t. fixed coordinates




L-to-R : interpret operations w.r.t local coordinates
) 90 ( ) 3 , ( = R T x T
) 90 ( R ) 3 , (x T
) 90 ( R ) 3 , (x T
(Column major convention)
Pivot-Point Rotation
Rotation with respect to a pivot point (x,y)
|
|
|
.
|

\
|

+
=
|
|
|
.
|

\
|

|
|
|
.
|

\
|

|
|
|
.
|

\
|
=

1 0 0
sin ) cos 1 ( cos sin
sin ) cos 1 ( sin cos
1 0 0
1 0
0 1
1 0 0
0 cos sin
0 sin cos
1 0 0
1 0
0 1
) , ( ) ( ) , (
u u u u
u u u u
u u
u u
u
x y
y x
y
x
y
x
y x T R y x T
Fixed-Point Scaling
Scaling with respect to a fixed point (x,y)

|
|
|
.
|

\
|


=
|
|
|
.
|

\
|

|
|
|
.
|

\
|

|
|
|
.
|

\
|
=

1 0 0
) 1 ( 0
) 1 ( 0
1 0 0
1 0
0 1
1 0 0
0 0
0 0
1 0 0
1 0
0 1
) , ( ) , ( ) , (
y s s
x s s
y
x
s
s
y
x
y x T s s S y x T
y y
x x
y
x
y x
Scaling Direction
Scaling along an arbitrary axis
) ( ) , ( ) (
1
u u R s s S R
y x

) (
1
u

R
) , (
y x
s s S
) (u R
Properties of Affine Transformations
Any affine transformation between 3D spaces can be
represented as a combination of a linear transformation
followed by translation

An affine transf. maps lines to lines

An affine transf. maps parallel lines to parallel lines

An affine transf. preserves ratios of distance along a line

An affine transf. does not preserve absolute distances
and angles
Review of Affine Frames
A frame is defined as a set of vectors {vi | i=1, , N}
and a point o
Set of vectors {vi} are bases of the associate vector
space
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
N N
c c c v v v o p + + + + =
2 2 1 1
N N
c c c v v v v + + + =
2 2 1 1
Changing Frames
Affine transformations as a change of frame
( ) y x,
0
v
1
v
( ) ( )
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
' ' '
+ + =
'
+
' '
+
' '
1 1
1 0 1 0
1 0 1 0
y
x
y
x
y x y x
o v v o v v
o v v o v v
0
v
'
1
v
'
o
o
'
Changing Frames
Affine transformations as a change of frame
o v v o
v v v
v v v
'
+
'
+
'
=
'
+
'
=
'
+
'
=
1 0 0
1 1 0 0 1
1 1 0 0 0
c c
b b
a a
( ) ( )
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
|
|
|
.
|

\
|
|
|
|
.
|

\
|
' ' =
|
|
|
.
|

\
|
'
'
' '
1 1 0 0 1
1 1 0 0 1
1 1 1
0 0 0
1 1 1
0 0 0
1 0 1 0
y
x
c b a
c b a
y
x
y
x
c b a
c b a
y
x
o v v o v v
( ) y x,
0
v
1
v
0
v
'
1
v
'
o
o
'
Changing Frames
In case the xyz system has standard bases
Rigid Transformations
A rigid transformation T is a mapping between
affine spaces
T maps vectors to vectors, and points to points
T preserves distances between all points
T preserves cross product for all vectors (to avoid
reflection)
In 3-spaces, T can be represented as

1 det and
where , ) (
1 3 1 3 3 3
= = =
+ =

R I R R RR
T p R p
T T
T
Rigid Body Rotation
Rigid body transformations allow only rotation
and translation

Rotation matrices form SO(3)
Special orthogonal group
I R R RR = =
T T
1 det = R
(Distance preserving)
(No reflection)
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 the
vectors of the principle axes of the rotated
coordinate frame
I R R RR = =
T T
3D Rotation About Arbitrary Axis
3D Rotation About Arbitrary Axis
1. Translation : rotation axis passes through the
origin

2. Make the rotation axis on the z-axis


3. Do rotation

4. Rotation & translation
) , , (
1 1 1
z y x T
) ( ) ( | o
y x
R R
) (u
z
R
) ( ) (
1 1
1
o |


x y
R R T
3D Rotation About Arbitrary Axis
Rotate u onto the z-axis
3D Rotation About Arbitrary Axis
Rotate u onto the z-axis
u: Project u onto the yz-plane to compute angle o
u: Rotate u about the x-axis by angle o
Rotate u onto the z-axis
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)
2 2
cos
c b
c
z
z
+
=
'

'
=
u u
u u
o
b
x
z x z
=
'
=
'
u
u u u u u o sin
2 2
sin
c b
b b
z
+
=
'
=
u u
o
3D Rotation About Arbitrary Axis
Rotate u about the x-axis onto the z-axis
Since we know both cos o and sin o, the rotation
matrix can be obtained





Or, we can compute the signed angle o


Do not use acos() since its domain is limited to [-1,1]
|
|
|
|
|
|
.
|

\
|
+ +
+

+
=
1 0 0 0
0 0
0 0
0 0 0 1
) (
2 2 2 2
2 2 2 2
c b
c
c b
b
c b
b
c b
c
x
o R
) , ( atan2
2 2 2 2
c b
b
c b
c
+ +
Euler angles
Arbitrary orientation can be represented by three
rotation along x,y,z axis
(
(
(
(

+
+
=
=
1 0 0 0
0
0
0 C S - S S C C C

) ( ) ( ) ( ) , , (
| | |
o | o o | o | o
o | o o | o | o
| o o |
C C S C S
S C C S S C C S S S C S
S S C S C
R R R R
x y z XYZ
Gimble
Hardware implementation of Euler angles
Aircraft, Camera
Euler Angles
Rotation about three
orthogonal axes
12 combinations
XYZ, XYX, XZY, XZX
YZX, YZY, YXZ, YXY
ZXY, ZXZ, ZYX, ZYZ

Gimble lock
Coincidence of inner most
and outmost gimbles rotation
axes
Loss of degree of freedom
Euler Angles
Euler angles are ambiguous
Two different Euler angles can represent the same
orientation



This ambiguity brings unexpected results of animation
where frames are generated by interpolation.
) ,
2
, 0 and ) 0 ,
2
,
2 1
u
t t
= = = ( R ( ) ,r ,r (r R
z y x
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
Taxonomy of Transformations
Projective
Affine
Rigid
Composition of Transforms
What is the composition of linear/affine/rigid
transformations ?

What is the linear (or affine) combination of
linear (or affine) transformations ?

What is the linear (or affine) combination of rigid
transformations ?
OpenGL Geometric Transformations
glMatrixMode(GL_MODELVIEW);
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
Hierarchical Modeling
A hierarchical model is created by nesting the
descriptions of subparts into one another to form a tree
organization
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
Programming Assignment #1
Create a hierarchical model using matrix stacks
The model should consists of three-dimensional
primitives such as polygons, boxes, cylinders,
spheres and quadrics.
The model should have a hierarchy of at least
three levels
Animate the model to show the hierarchical
structure
Eg) a car driving with rotating wheels
Eg) a runner with arms and legs swing
Make it aesthetically pleasing or technically
illustrative

Вам также может понравиться