Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Matrix calculus wikipedia , lookup

Homogeneous coordinates wikipedia , lookup

Four-vector wikipedia , lookup

Matrix multiplication wikipedia , lookup

Rotation matrix wikipedia , lookup

Symmetry in quantum mechanics wikipedia , lookup

Transcript
II 2D Transformation
Transformations
• Transformations are needed to:
– Position objects defined relative to the origin
– Build scenes based on hierarchies
– Project objects from three to two dimensions
• Transformations include:
–
–
–
–
Translation
Scaling
Rotation
Reflections
• Transformations can be represented by matrices
and matrix multiplication
II-1
 x
• Representation of Points: x y ;  
 y
• Transformation of Points
X T   x

a b 
*


y

(
ax

cy
)
(
bx

dy
)

x

c
d


y*

• Transformation of
Straight Lines
II-2
Rotation
• Consider rotation about the origin by q
degrees
– radius stays the same, angle increases by
q
x’ = r cos (f  q)
y’ = r sin (f  q)
x’=x cos q –y sin q
y’ = x sin q + y cos q
x = r cos f
y = r sin f
II-3
• The transformation for a general rotation
about the origin by an arbitrary angle q
 cos q
T   
 sin q
sin q 

cos q 
X   X T   x *
*
cos q
T   
 sin q
y *  x
 
sin q 

cos q 
 sin q 

cos q 
 x * cos q
X  T X      
 y *  sin q
*
 cos q
y 
 sin q
 sin q   x 



cos q   y 
II-4
Scaling
• Scaling increases or decreases the size of the
object
• Scaling occurs with respect to the origin
– If the object is not centered at the origin, it will move
in addition to changing size
• In general, this is done with the equations:
xn = s x * x
yn = s y * y
• This can also be done with the matrix
multiplication:
 xn  s x
y    0
 n 
0   x

s y   y 
II-5
• Example:
2 0
T    
0 2
3 0 
T   

0
1
/
2


II-6
Reflection
• corresponds to negative scale factors
sx = -1 sy = 1
original
sx = -1 sy = -1
sx = 1 sy = -1
II-7
• The reflection about the x-axis (y=0) is
obtained by
1 0 
T   

0

1


• The reflection about the y-axis (x=0) is
obtained by
  1 0
T   
0
1
• The reflection about the y=x is obtained by
0 1 
T    
1 0
• The reflection about the y=-x is obtained by
 0  1
T   


1
0


II-8
II-9
II-10
Translations
• The amount of the translation is added to or
subtracted from the x and y coordinates
• In general, this is done with the equations:
xn = x + tx
y n = y + ty
• This can also be done with the matrix
multiplication:
 xn  1 0 t x   x 
 y   0 1 t   y 
y 
 n 
 1  0 0 1   1 
xn
yn 1  x
1

y 1  0
t x

0
1
ty
0

0
1
II-11
Homogeneous Coordinates
• The two dimensional point (x, y) is represented by
the homogeneous coordinate (x, y, 1)
• Some transformations will alter this third
component so it is no longer 1
• In general, the homogeneous coordinate (x, y, w)
represents the two dimensional point (x/w, y/w)
• General transformation matrix:
 a b 0
T    c d 0
m n 1
a b m
T    c d n 
0 0 1 
II-12
Order of Transformations
• Matrix multiplication is not commutative so
changing the order of transformation can change
the result
• For example,
changing the
order of a
translation and
a rotation
produces a
different result:
II-13
II-14
II-15
II-16
• Rotation about an arbitrary point m n through
an angle q
x
*

y * 1  x
0 0  cos q
 1
y 1  0
1 0  sin q
 m  n 1  0
sin q
cos q
0
0  1 0 0
0  0 1 0
1 m n 1
II-17
II-18
II-19
II-20