Sie sind auf Seite 1von 42

Transformations and Matrices

Transformations are functions

Matrices are functions representations

Matrices represent linear transformation

{2x2 Matrices} {2D Linear


Transformation}
1
Transformations (1/3)

What are the!

chan"in" somethin" to somethin" else #ia rules


mathematics$ mappin" %et&een #alues in a ran"e
set and domain set (function/relation)

"eometric$ translate' rotate' scale' shear'(

Wh are the important to "raphics!

mo#in" o%)ects on screen / in space

mappin" from model space to screen space


specifin" parent/child relationships

(
2
Transformation (2/3)

Translation

Mo#in" an o%)ect

*cale

+han"in" the
si,e of an o%)ect
-cto%er 2.' 2/10 3
t

t
x
w
old
w
new
h
old
h
new
x
new
= x
old
+ t
x
; y
new
= y
old
+ t
y
s
x
=w
new
/w
old
s
y
=h
new
/h
old
x
new
= s
x
x
old
y
new
= s
y
y
old
Transformation (3/3)

To rotate a line
or pol"on' &e
must rotate
each of its
#ertices

*hear
-cto%er 2.' 2/10 0
(x')
Original Data y Shear x Shear
What is a 2D Linear
Transform!
. y and x vectors and a scalar for
, ) y ( T ) x ( aT ) y x a ( T : Definition


+ +
-cto%er 2.' 2/10 .
( ) )
y
,
x
2 ( )
y
,
x
2 (
y y
),
x
x (
2
: say 2, by x, in Scale
1
1
0
0
1 0
1
0
+ +
+
Example
1xample
-cto%er 2.' 2/10 2
) ,
0 0
( y x
) ,
0 0
2 ( y x
) ,
1 1
( y x ) ,
1 1
2 ( y x
y
x
x
y
) ,
0 0
2 ( y x
) ,
1 1
2 ( y x
( ) y y
x x
1 0
1 0
,
2
2 +
+
y
) ,
0 0
( y x
) ,
1 1
( y x
( ) y y
x
x
1 0
1
0
), ( 2 +
+
( ) y y
x
x
1 0
1
0
), ( +
+
x
y
( ) y y
x
x
1 0
1
0
), ( 2 +
+
( ) y y
x
x
1 0
1
0
), ( +
+
y
x
( ) y y
x x
1 0
1 0
,
2
2 +
+
Scale in x by 2
( ) y y
x x
1 0
1 0
), ( 2 +
+
( ) y y
x x
1 0
1 0
), ( 2 +
+
Transformations: Translation (1/2)

3 translation is a
strai"ht line
mo#ement of an
o%)ect from one
position to another4

3 point (x') is
transformed to the
point (x5'5) %
addin" the
translation
distances T
x
and T

$

-cto%er 2.' 2/10 6
x = x + T
x
y = y + T
y
Transformations: Translation(2/2)

mo#in" a point
% a "i#en t
x
and
t

amount
e4"4 point 7 is
translated to
point 75
mo#in" a line
% a "i#en t
x
and
t

amount

translate each of
the 2 endpoints
-cto%er 2.' 2/10 8
) 10 , 5 ( P
) 10 , 15 ( P
1
]
1

1
]
1

0
10
y
x
t
t
T
) 20 , 5 ( 1 P
) 10 , 5 ( 2 P ) 10 , 5 ( 1 P
) 0 , 5 ( 2 P
1
]
1

1
]
1

10
0
y
x
t
t
T
Transformations: Rotation (1/)

-%)ects rotated accordin" to angle of


rotation theta ()

*uppose a point 7(x') is transformed to the


point 79(x9'9) % an anti:cloc;&ise rotation
a%out the ori"in % an an"le of de"rees'
then$
-cto%er 2.' 2/10 <
Given x = r cos , y = r sin
x = x cos y sin
y = y sin + y cos
Transformations: Rotation (2/)

=otation 7 % anticloc;&ise relati#e to


ori"in (/'/)
-cto%er 2.' 2/10 1/
) 0 , 0 (
) , ( y x P

) , ( y x P

x
y
r
) 0 , 0 (
) , ( y x P
Transformations: Rotation (!/)
=otation a%out an ar%itar pi#ot point (x
=
'
=
)
*tep 1$ translation of the o%)ect % (:x
=
':
=
)
x
1
= x - x
R
y
1
= y - y
R
*tep 2$ rotation a%out the ori"in
x
2
= x
1
cos() - y
1
sin ()
y
2
= y
1
cos() - x
1
sin ()
*tep 3$ translation of the rotated o%)ect % (x='=)
x = x
r
+ x
2
y = y
r
+ y
2
-cto%er 2.' 2/10 11
Transformations: Rotation (/)

o%)ect can %e
rotated around
an ar%itrar
point (x
r
'
r
)
;no&n as
rotation or
pivot point
%$
-cto%er 2.' 2/10 12
x' = x
r
+ (x - x
r
) cos() - (y - y
r
) sin ()
y' = y
r
+ (x - x
r
) sin ()+(y - y
r
) cos()
Transformations: S"aling (1/#)

*calin" chan"es the size of an o%)ect


3chie#ed % applin" scaling factors s
x

and s

*calin" factors are applied to the > and


?
co:ordinates of points de@nin" an
o%)ect5s
-cto%er 2.' 2/10 13
Transformations: S"aling (2/#)
uniform scalin" is produced &hen s
x

and s

ha#e same #alue i4e4 s


x
A s

non-uniform scalin" is produced &hen


s
x
and s
x
are not eBual : e4"4 an ellipse
from a circle4
i4e4 s
x
s


-cto%er 2.' 2/10 10
x
2
= s
x
x
1
y
2
= s
y
y
1
Transformations: S"aling (!/#)
*imple scalin" :
relati#e to (/'/)
Ceneral form$
-cto%er 2.' 2/10 1.
y s y
x s x
y
x

) , ( 1 y x P
) , ( 1 y x P
) ! , 2 ( 1 P
) 1 , ! ( 2 P
) ! , " ( 1 P
) 1 , # ( 2 P
Ex: s
x
$ 2 an% s
y
$1
Transformations: S"aling (/#)
Df the point (x
f
'
f
) is to %e the @xed point' the
transformation is$
x9 A x
f
E (x : x
f
) *
x
9 A
f
E ( :
f
) *

This can %e rearran"ed to "i#e$


x9 A x *
x
E (1 : *
x
) x
f
9 A *

E (1 : *

)
f
&hich is a com%ination of a scalin" a%out the
ori"in and a translation4
-cto%er 2.' 2/10 12
Transformations: S"aling (#/#)
-cto%er 2.' 2/10 16
Transformation as Matrices
-cto%er 2.' 2/10 18
S"ale:
x = s
x
x
y = s
y
y
Rotation:
x = xcos - ysin
y = xsin + ycos
Translation:
x = x + t
x
y = y + t
y
1
]
1

1
]
1

1
]
1

y s
x s
y
x
s
s
y
x
y
x
0
0
1
]
1

1
]
1

1
]
1






cos sin
sin cos
cos sin
sin cos
y x
y x
y
x
1
]
1

+
+

1
]
1

+
1
]
1

y
x
y
x
t y
t x
y
x
t
t
Transformations: Shear (1/2)
*hear in x:
-cto%er 2.' 2/10 1<
1
]
1

1
]
1

1
]
1

y
ay x
y
x a
Sh
x
1 0
1
) 0 , 1 (
) 1 , ( a
) 1 , 0 (
) 0 , 1 (
) 1 , 1 (
Transformations: Shear (2/2)
*hear in $
-cto%er 2.' 2/10 2/
) 1 , 0 (
) 0 , 0 (
) , 1 ( b
) 1 , 0 (
) 0 , 1 (
) 0 , 0 (
) 1 , 1 (
1
]
1

1
]
1

1
]
1

y bx
x
y
x
b
Sh
y
1
0 1
Shear in x then in y
-cto%er 2.' 2/10 21
) 1 , 0 (
) 0 , 0 (
) 1 , 0 (
) 0 , 0 (
) 1 , 0 (
) 0 , 0 (
) 0 , 1 (
) 0 , 1 (
) , (1 b ab +
) , ( 1 a
) , ( 1 ab a

) , ( 1 1 b ab a + + +
) , ( 1 1 a +
) 1 , 0 (
) 0 , 0 (
) 1 , 1 ( b +
) 1 , 1 (
) , 1 ( b
Shear in y then in x
-cto%er 2.' 2/10 22
) 1 , 0 (
) 0 , 0 (
) 1 , 0 (
) 1 , 0 (
) 0 , 0 (
) 0 , 1 ( ) 0 , 1 (
) , (1 b +
) , ( 1 a
) , ( 1 ab a +
) , ( 1 1 ab b a + + +
) , ( 1 1 a +
) 1 , 0 (
) 0 , 0 (
) 1 , 1 ( b +
) 1 , 1 (
) , 1 ( b
&omogeneo's "oor%inate

3s translations do not ha#e a 2 x 2 matrix


representation' &e introduce homo"eneous
coordinates to allo& a 3 x 3 matrix
representation4

The Fomo"eneous coordinate correspondin" to


the point (x') is the triple (x
h
'
h
' &) &here$
x
h
A &x

h
A &
Gor the t&o dimensional transformations &e can
set & A 14
-cto%er 2.' 2/10 23
Matrix representation
-cto%er 2.' 2/10 20
1
1
1
]
1

1
) , (
y
x
P
y x
1
1
1
]
1

1 0 0
0 0
0 0
, y
x
y x
s
s
S
1
1
1
]
1

1 0 0
0 cos sin
0 sin cos

R
1
1
1
]
1

1 0 0
1 0
0 1
, y
x
y x
t
t
T
Hasic Transformation (1/3)

Translation
-cto%er 2.' 2/10 2.
Hasic Transformation (2/3)

=otation
-cto%er 2.' 2/10 22

_
,

P x y x y
t t
t t PS t ( , , ) ( , , )
cos sin
sin cos ( ) 1 1
0
0
0 0 1
Hasic Transformation (3/3)

*calin"
-cto%er 2.' 2/10 26
+omposite Transformation
-cto%er 2.' 2/10 28
S'ppose (e (ishe%
to perform m'ltiple
transformations on a
point:
P
2
T
3,1
P
1
P
3
S
2, 2
P
2
P
4
R
30
P
3
M R
30
S
2,2
T
3,1
P
4
MP
1
1xample of +omposite
Transformation(1/3)

3 scalin" transformation at an ar%itrar an"le is


a com%ination of t&o rotations and a scalin"$
=(:t) *(*
x
'*

) =(t)
3 rotation a%out an ar%itrar point (x
f
'
f
) % and
an"le t anti:cloc;&ise has matrix$
T(:x
f
':
f
) =(t) T(x
f
'
f
)
-cto%er 2.' 2/10 2<
1xample of +omposite
Transformation(2/3)
=eIection a%out the :axis=eIection a%out the x:
axis
-cto%er 2.' 2/10 3/
1
1
1
]
1

1 0 0
0 1 0
0 0 1
1
1
1
]
1

1 0 0
0 1 0
0 0 1
1xample of +omposite
Transformation(3/3)
-cto%er 2.' 2/10 31
Refle"tion a)o't the origin Refle"tion a)o't the line y$x
1
1
1
]
1

1 0 0
0 1 0
0 0 1
1
1
1
]
1

1 0 0
0 0 1
0 1 0
3D Transformation
-cto%er 2.' 2/10 32
J
>
?
?
>
J
Hasic 3D Transformations

Translation

*cale

=otation

*hear

3s in 2D' &e use homo"eneous coordinates


(x'','&)' so that transformations ma %e
composited to"ether #ia matrix multiplication4
-cto%er 2.' 2/10 33
3D Translation and *calin"
T7 A (x E t
x
' E t

' , E t
,
)
*7 A (s
x
x' s

' s
,
,)
-cto%er 2.' 2/10 30
1
1
1
1
]
1

1 0 0 0
1 0 0
0 1 0
0 0 1
z
y
x
t
t
t
1
1
1
1
]
1

1
z
y
x
1
1
1
1
]
1

1 0 0 0
0 0 0
0 0 0
0 0 0
z
y
x
s
s
s
1
1
1
1
]
1

1
z
y
x
3D =otation (1/0)
7ositi#e =otations are de@ned as follo&s$
3xis of rotation is Direction of positi#e
rotation is
x to ,
, to x
, x to
-cto%er 2.' 2/10
204481 Foundation of Computer Grap
hics
3.
3D =otation (2/0)

=otation a%out x:axis =


x
($)7
-cto%er 2.' 2/10 32
1
1
1
1
]
1

1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1


1
1
1
1
]
1

1
z
y
x
y
z

) 0 , 1 , 0 (
) 1 , 0 , 0 (

3D =otation (3/0)

=otation a%out :axis =

($)7
-cto%er 2.' 2/10 36
1
1
1
1
]
1

1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos


1
1
1
1
]
1

1
z
y
x

x
z
) 0 , 0 , 1 (
) 1 , 0 , 0 (

3D =otation (0/0)

=otation a%out ,:axis =


,
(K)7
-cto%er 2.' 2/10 38
1
1
1
1
]
1


1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos


1
1
1
1
]
1

1
z
y
x
3D *hear
x *hear$ *F
x
7
-cto%er 2.' 2/10 3<
1
1
1
1
]
1

1 0 0 0
0 1 0 0
0 1 0
0 0 1
y
x
sh
sh
1
1
1
1
]
1

1
z
y
x
x
z
y
x
z
y
=otation 3%out 3n 3r%itar
3xis (1/3)
14 Translate one end of
the axis to the
ori"in
24 =otate a%out the :
axis and an"le
34 =otate a%out the x:
axis throu"h an
an"le
-cto%er 2.' 2/10 0/
Z
P
1
P
2
Y
X
b
a
c
u
1
u
2
u
3

U
=otation 3%out 3n 3r%itar
3xis (2/3)
-cto%er 2.' 2/10 01
Z
P
1
P
2
Y
X
b
a
c
u
1
u
2
u
3

U
Z
Y
X
b
a
c
u
1
u
2
u
3

U
Z
Y

a
u
2
X
04 When L is ali"ned &ith the ,:axis' appl the ori"inal rotation' = ='
a%out the ,:axis4
.4 3ppl the in#erses of the transformations in re#erse order4
=otation 3%out 3n 3r%itar
3xis (3/3)
-cto%er 2.' 2/10 02
T
:1
=

($) =
x
(:%) = =
x
(%) =

(:$) T 7

Das könnte Ihnen auch gefallen