Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Modeling Transformations
Courtesy of Adam Finkelstein, Princeton University
Modeling Transformations• Specify transformations for objects
o Allows definitions of objects in own coordinate systemso Allows use of object definition multiple times in a scene
H&B Figure 109
Overview• 2D Transformations
o Basic 2D transformationso Matrix representationo Matrix composition
• 3D Transformationso Basic 3D transformationso Same as 2D
• Transformation Hierarchieso Scene graphso Ray casting
2D Modeling Transformations
ScaleRotate
Translate
ScaleTranslate
x
y
World Coordinates
ModelingCoordinates
2D Modeling Transformations
x
y
World Coordinates
ModelingCoordinates
Let’s lookat this indetail…
2D Modeling Transformations
x
y
ModelingCoordinates
2D Modeling Transformations
x
y
ModelingCoordinates
Scale .3, .3Rotate -90
Translate 5, 3
2D Modeling Transformations
x
y
ModelingCoordinates
Scale .3, .3Rotate -90
Translate 5, 3
2D Modeling Transformations
x
y
ModelingCoordinates
Scale .3, .3Rotate -90
Translate 5, 3
World Coordinates
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
Basic 2D Transformations• Rotation:
o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
Trigonometric identity for the sum of two angles:sin(φ+θ) = sin φ cos θ + cos φ sin θcos(φ+θ) = cos φ cos θ - sin φ sin θ
(x*,y*)
(x’,y’)
φθ
r
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
Transformations can be combined
(with simple algebra)
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sxo y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
x’ = x*sxy’ = y*syx’ = x*sxy’ = y*sy
(x,y)(x’,y’)
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
x’ = (x*sx)*cosΘ − (y*sy)*sinΘy’ = (x*sx)*sinΘ + (y*sy)*cosΘx’ = (x*sx)*cosΘ − (y*sy)*sinΘy’ = (x*sx)*sinΘ + (y*sy)*cosΘ
(x’,y’)
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
x’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + tyx’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty
(x’,y’)
Basic 2D Transformations• Translation:
o x’ = x + txo y’ = y + ty
• Scale:o x’ = x * sx o y’ = y * sy
• Shear:o x’ = x + hx*yo y’ = y + hy*x
• Rotation:o x’ = x*cosΘ - y*sinΘo y’ = x*sinΘ + y*cosΘ
x’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + tyx’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty
Overview• 2D Transformations
o Basic 2D transformationso Matrix representationo Matrix composition
• 3D Transformationso Basic 3D transformationso Same as 2D
• Transformation Hierarchieso Scene graphso Ray casting
Matrix Representation• Represent 2D transformation by a matrix
• Multiply matrix by column vector⇔ apply transformation to point
=
yx
dcba
yx''
dcba
dycxybyaxx
+=+=
''
Matrix Representation• Transformations combined by multiplication
=
yx
lkji
hgfe
dcba
yx
''
Matrices are a convenient and efficient way to represent a sequence of transformations!
=
yx
dcba
yx''
2x2 Matrices• What types of transformations can be
represented with a 2x2 matrix?
2D Identity?
yyxx
==''
=
yx
yx
1001
''
2D Scale around (0,0)?
ysyyxsxx
*'*'
==
=
yx
dcba
yx''
=
yx
sysx
yx
00
''
2x2 Matrices• What types of transformations can be
represented with a 2x2 matrix?
2D Rotate around (0,0)?
yxyyxx
*cos*sin'*sin*cos'
Θ+Θ=Θ−Θ=
=
yx
dcba
yx''
ΘΘΘ−Θ=
yx
yx
cossinsincos
''
2D Shear?
yxshyyyshxxx
+=+=
*'*'
=
yx
dcba
yx''
=
yx
shyshx
yx
11
''
2x2 Matrices• What types of transformations can be
represented with a 2x2 matrix?
2D Mirror over Y axis?
yyxx
=−=
''
=
yx
dcba
yx''
−=
yx
yx
1001
''
2D Mirror over (0,0)?
yyxx
−=−=
''
=
yx
dcba
yx''
−−=
yx
yx
1001
''
=
yx
dcba
yx''
2x2 Matrices• What types of transformations can be
represented with a 2x2 matrix?
2D Translation?
tyyytxxx
+=+=
''
Only linear 2D transformations can be represented with a 2x2 matrix
NO!
Linear Transformations• Linear transformations are combinations of …
o Scale,o Rotation,o Shear, ando Mirror
• Properties of linear transformations:o Satisfies:o Origin maps to origino Lines map to lineso Parallel lines remain parallelo Ratios are preservedo Closed under composition
)()()( 22112211 pppp TsTsssT +=+
=
yx
dcba
yx
''
2D Translation• 2D translation represented by a 3x3 matrix
o Point represented with homogeneous coordinates
tyyytxxx
+=+=
''
=
11001001
1''
yx
tytx
yx
Homogeneous Coordinates• Add a 3rd coordinate to every 2D point
o (x, y, w) represents a point at location (x/w, y/w)o (x, y, 0) represents a point at infinityo (0, 0, 0) is not allowed
1 2
1
2 (2,1,1) or (4,2,2) or (6,3,3)
Convenient coordinate system to represent many useful transformations
x
y
Basic 2D Transformations• Basic 2D transformations as 3x3 matrices
ΘΘΘ−Θ
=
11000cossin0sincos
1''
yx
yx
=
11001001
1''
yx
tytx
yx
=
11000101
1''
yx
shyshx
yx
Translate
Rotate Shear
=
11000000
1''
yx
sysx
yx
Scale
Affine Transformations• Affine transformations are combinations of …
o Linear transformations, ando Translations
• Properties of affine transformations:o Origin does not necessarily map to origino Lines map to lineso Parallel lines remain parallelo Ratios are preservedo Closed under composition
=
wyx
fedcba
wyx
100''
Projective Transformations• Projective transformations …
o Affine transformations, ando Projective warps
• Properties of projective transformations:o Origin does not necessarily map to origino Lines map to lineso Parallel lines do not necessarily remain parallelo Ratios are not preserved (but “cross-ratios” are)o Closed under composition
=
wyx
ihgfedcba
wyx
'''
Overview• 2D Transformations
o Basic 2D transformationso Matrix representationo Matrix composition
• 3D Transformationso Basic 3D transformationso Same as 2D
• Transformation Hierarchieso Scene graphso Ray casting
Matrix Composition• Transformations can be combined by
matrix multiplication
ΘΘΘ−Θ
=
wyx
sysx
tytx
wyx
1000000
1000cossin0sincos
1001001
'''
p’ = T(tx,ty) R(Θ) S(sx,sy) p
Matrix Composition• Matrices are a convenient and efficient way to
represent a sequence of transformationso General purpose representationo Hardware matrix multiplyo Efficiency with premultiplication
» Matrix multiplication is associative
p’ = (T * (R * (S*p) ) )p’ = (T*R*S) * p
Matrix Composition• Be aware: order of transformations matters
» Matrix multiplication is not commutative
p’ = T * R * S * p
“Global” “Local”
Matrix Composition• Rotate by Θ around arbitrary point (a,b)
o M=T(a,b) * R(Θ) * T(-a,-b)
• Scale by sx,sy around arbitrary point (a,b)o M=T(a,b) * S(sx,sy) * T(-a,-b)
(a,b)
(a,b)
The trick:First, translate (a,b) to the origin.Next, do the rotation about origin.Finally, translate back.
(Use the same trick.)
Overview• 2D Transformations
o Basic 2D transformationso Matrix representationo Matrix composition
• 3D Transformationso Basic 3D transformationso Same as 2D
• Transformation Hierarchieso Scene graphso Ray casting
3D Transformations• Same idea as 2D transformations
o Homogeneous coordinates: (x,y,z,w) o 4x4 transformation matrices
=
wzyx
ponmlkjihgfedcba
wzyx
''''
Basic 3D Transformations
=
wzyx
wzyx
1000010000100001
'''
=
wzyx
tztytx
wzyx
1000100010001
'''
=
wzyx
szsy
sx
wzyx
1000000000000
'''
−=
wzyx
wzyx
1000010000100001
'''
Identity Scale
Translation Mirror over X axis
Basic 3D Transformations
ΘΘΘ−Θ
=
wzyx
wzyx
1000010000cossin00sincos
'''
Rotate around Z axis:
ΘΘ
Θ−Θ=
wzyx
wzyx
10000cos0sin00100sin0cos
'''
Rotate around Y axis:
ΘΘΘ−Θ=
wzyx
wzyx
10000cossin00sincos00001
'''
Rotate around X axis:
Overview• 2D Transformations
o Basic 2D transformationso Matrix representationo Matrix composition
• 3D Transformationso Basic 3D transformationso Same as 2D
• Transformation Hierarchieso Scene graphso Ray casting
Angel Figures 8.8 & 8.9
Transformation Hierarchies• Scene may have hierarchy of coordinate systems
o Each level stores matrixrepresenting transformation from parent’s coordinate system
Base[M1]
Upper Arm[M2]
Lower Arm[M3]
Robot Arm
Transformation Example 1
Rose et al. `96
• Well-suited for humanoid characters
Root
LHip
LKnee
LAnkle
RHip
RKnee
RAnkle
Chest
LCollar
LShld
LElbow
LWrist
LCollar
LShld
LElbow
LWrist
Neck
Head
Transformation Example 1
Mike Marr, COS 426, Princeton University, 1995
Transformation Example 2• An object may appear in a scene multiple times
Draw same 3D data with different transformations
Transformation Example 2
Building
Floor 4 Floor5Floor 3Floor 2Floor 1
Chair KBookshelf 1
Desk ChairBookshelf
Desk 1 Desk 2 Chair 1
Floor Furniture
Office NOffice 1
Office Furniture
DefinitionsDefinitions
InstancesInstances
Angel Figures 8.8 & 8.9
Ray Casting With Hierarchies• Transform rays, not primitives
o For each node ...» Transform ray by inverse of matrix» Intersect with primitives» Transform hit by matrix
Base[M1]
Upper Arm[M2]
Lower Arm[M3]
Robot Arm
Summary• Coordinate systems
o World coordinateso Modeling coordinates
• Representations of 3D modeling transformationso 4x4 Matrices
» Scale, rotate, translate, shear, projections, etc.» Not arbitrary warps
• Composition of 3D transformationso Matrix multiplication (order matters)o Transformation hierarchies