Post on 28-Aug-2018
computer graphics • transforms © 2009 fabio pellacini • 2
linear algebra review
• matrices – notation – basic operations – matrix-vector multiplication
computer graphics • transforms © 2009 fabio pellacini • 3
matrices
• notation for matrices and vectors – use column form for vectors
€
M =m11 m12m21 m22
"
# $
%
& ' = mij[ ] [ ]Tvv
vv
212
1 =!"
#$%
&=v
computer graphics • transforms © 2009 fabio pellacini • 4
matrix operations
• addition
• scalar multiply
][][ ijijij nmtNMT +=⇒+=
][][ ijij mtMT αα =⇒=
computer graphics • transforms © 2009 fabio pellacini • 5
matrix operations
• matrix-matrix multiply – row-column multiplication – not commutative – associative
!"
#$%
&=⇒= ∑
kkjikij nmtMNT ][
!"
#$%
&!"
#$%
&=!
"
#$%
&
2221
1211
2221
1211
2221
1211
nnnn
mmmm
tttt
computer graphics • transforms © 2009 fabio pellacini • 6
matrix operations
• matrix-vector multiply – row-column multiplication
!"
#$%
&=⇒= ∑
kkiki vmuM ][vu
!"
#$%
&!"
#$%
&=!
"
#$%
&
2
1
2221
1211
2
1
vv
mmmm
uu
computer graphics • transforms © 2009 fabio pellacini • 7
special matrices
• identity
• zero
[ ]!"#
≠
===
j ifor 0
jifor1ijiI !
"
#$%
&=
1001
I
MIMMI ==
[ ] 0== ijoO !"
#$%
&=
0000
O
MOM =+
computer graphics • transforms © 2009 fabio pellacini • 8
matrix operations
• transpose – flip along the diagonal
• inverse – will not compute explicitly in this course
][][ jiijT mtMT =⇒=
IMMMMTMMT ===⇒= −−− 111
computer graphics • transforms © 2009 fabio pellacini • 9
matrix operations oroperties
• linearity of multiplication
• associativity of multiplication
• transpose and inverse of matrix multiply
MBMABAMBABA
βαβα
ααα
+=+
+=+
)()(
111)()(
−−− =
=
ABABABAB TTT
CABBCA )()( =
computer graphics • transforms © 2009 fabio pellacini • 10
geometric transformation
• function that maps points to points
• different transformations have restriction on the form of X – we will look at linear, affine and projections
)(' ppp X=→
computer graphics • transforms © 2009 fabio pellacini • 12
translation
• simplest form • inverse
tppt +=)(Ttppp tt −== −
− )()(1 TT
computer graphics • transforms © 2009 fabio pellacini • 13
linear transformation
• fundamental property
• can be represented in matrix form
• other properties – maps origin to origin – maps lines to lines – parallel lines remain parallel – length ratios are preserved – closed under composition
)()()( qpqp XXX βαβα +=+
pp MX =)(
computer graphics • transforms © 2009 fabio pellacini • 14
uniform scale
!"
#$%
&=!
"
#$%
&!"
#$%
&=
y
x
y
xs sp
sppp
ss
S00
p
ss SS /11 =−
computer graphics • transforms © 2009 fabio pellacini • 15
non-uniform scale
!"
#$%
&=!
"
#$%
&!"
#$%
&=
yy
xx
y
x
y
x
psps
pp
ss
S0
0ps
)/1,/1(1
yx ssSS =−s
computer graphics • transforms © 2009 fabio pellacini • 16
rotation
!"
#$%
&+
−=!
"
#$%
&!"
#$%
& −=
θθ
θθ
θθ
θθθ cossin
sincos
cossinsincos
yx
yx
y
x
pppp
pp
R p
θθ −− = RR 1
computer graphics • transforms © 2009 fabio pellacini • 17
shear
!"
#$%
&+
+=!
"
#$%
&!"
#$%
&=
yxy
yxx
y
x
y
x
ppspsp
pp
ss
Sh1
1ps
computer graphics • transforms © 2009 fabio pellacini • 18
reflection
!"
#$%
&−=!
"
#$%
&!"
#$%
&−=
y
x
y
xx p
ppp
Rl1001
p
!"
#$%
&−
−=!
"
#$%
&!"
#$%
&−
−=
y
x
y
xo p
ppp
Rl1001
p
...=pyRl
computer graphics • transforms © 2009 fabio pellacini • 19
combining translation and linear transforms
• represent linear together with translation – rigid body transformation are a subset of this
• goal: unified format for all transformations
tppt +=MXM )(,
computer graphics • transforms © 2009 fabio pellacini • 20
homogeneous coordinates
• represent points with 1 additional coordinate w – set it to 1 for points
!!!
"
#
$$$
%
&=
!!!
"
#
$$$
%
&=
1y
x
w
y
x
pp
ppp
p
computer graphics • transforms © 2009 fabio pellacini • 21
homogeneous coordinates
• represent translation with a 3x3 matrix
• add one row and column to linear transforms
!!!
"
#
$$$
%
&+
+
=
!!!
"
#
$$$
%
&
!!!
"
#
$$$
%
&=
111001001
yy
xx
y
x
y
x
tptp
pp
tt
T pt
!!!
"
#
$$$
%
&+
+
=
!!!
"
#
$$$
%
&
!!!
"
#
$$$
%
&=
1110000
2221
1211
2221
1211
yx
yx
y
x
pmpmpmpm
pp
mmmm
Mp
computer graphics • transforms © 2009 fabio pellacini • 22
affine transformations
• combining linear and translation in one matrix
• properties – does not map origin to origin – maps lines to lines – parallel lines remain parallel – length ratios are preserved – closed under composition
!"
#$%
&!"
#$%
&=+=
110pt
tppM
MX
computer graphics • transforms © 2009 fabio pellacini • 23
affine transformations
!!!
"
#
$$$
%
&=
1001001
y
x
tt
Tt
!!!
"
#
$$$
%
&=
1000000
y
x
ss
Ss
!!!
"
#
$$$
%
& −
=
1000cossin0sincos
θθ
θθ
θR
translation
scale
rotation
computer graphics • transforms © 2009 fabio pellacini • 24
compositing transformations
• applying one transformation after another – expressed by function composition
• for the transforms presented before, computed by matrix multiplication
))(())((' 1212 ppp XXXX ==
))(()())(())(( 12121212 pppp MMMMXXXX ===
computer graphics • transforms © 2009 fabio pellacini • 25
compositing transformations
• translation
• linear transformations
• affine transformations
!"
#$%
&!"
#$%
& +=!
"
#$%
&!"
#$%
&!"
#$%
&11011010
2112 pttptt III
!"
#$%
&!"
#$%
&=!
"
#$%
&!"
#$%
&!"
#$%
&110
0110
0100 1212 pp MMMM
!"
#$%
&!"
#$%
& +=!
"
#$%
&!"
#$%
&!"
#$%
&11011010
212121122 pttptt MMMMM
computer graphics • transforms © 2009 fabio pellacini • 26
compositing transformations
• composition is not commutative
rotate, then translate
translate, then rotate
computer graphics • transforms © 2009 fabio pellacini • 27
compositing transformations
• composition is not commutative
rotate, then translate
translate, then rotate
computer graphics • transforms © 2009 fabio pellacini • 28
compositing transformations
• composition is not commutative
rotate, then translate
translate, then rotate
computer graphics • transforms © 2009 fabio pellacini • 29
complex transformation
• often represented as combination of simpler ones – intuitive geometric interpretation
• rotation around arbitrary axis – translate to axis center – rotate – translate back
aaa −= TRTR θθ,
computer graphics • transforms © 2009 fabio pellacini • 34
transforming points and vectors
• points and vectors are different entities – vectors: encode direction (difference of points) – points: encode position (origin plus a vector)
• points and vector transform differently – we have shown how points transforms previously – vectors simply ignore the translation
)()()()()()()(
qptqtpqpvtpp
qpv
−=+−+=−=
+=
−=
MMMXXXMX
computer graphics • transforms © 2009 fabio pellacini • 35
transforming points and vectors
• use homogeneous coordinates with w=0
• everything is consistent!
• but what is that “w” anyway?
!"
#$%
&=!
"
#$%
&!"
#$%
&0010vvt MM
computer graphics • transforms © 2009 fabio pellacini • 36
homogeneous coordinates
• points – will become useful later on
• vectors
!!!
"
#
$$$
%
&≡
!!!
"
#
$$$
%
&≡
wwpwp
pp
pp y
x
y
x
yx
1),(
!!!
"
#
$$$
%
&≡
0),( y
x
yx vv
vv
computer graphics • transforms © 2009 fabio pellacini • 37
coordinate systems review
• points are represented wrt a coordinate system – cartesian coordinates in the canonical coord. system
• canonical coordinate system
ypyxpxoyxopp )()(),( ⋅+⋅+=++=⇔= yxyx pppp
)1,0()0,1()0,0(
=
=
=
yxo
computer graphics • transforms © 2009 fabio pellacini • 38
coordinate system review
• write a point in a new coordinate system
• can be represented as an affine matrix multiply
'''''')'(')'(')','(' yxoypyxpxopp yxyx pppp ++=⋅+⋅+=⇔=
!"
#$%
&!"
#$%
&=!
"
#$%
&=!
"
#$%
&
!!!
"
#
$$$
%
&
!!!
"
#
$$$
%
&=
!!!
"
#
$$$
%
&=
!!!
"
#
$$$
%
&
1'
100'''
1'
1
1''
100''''''
1''
1poyxpp
M
pp
oyxoyx
pp
Mpp
y
x
yyy
xxx
y
x
y
x
computer graphics • transforms © 2009 fabio pellacini • 39
coordinate system review
• an affine transform is a change of coord. system – another interpretation for combination of transforms
• what is the matrix I should use to change coord? – just invert previous definition
• i.e. invert combination of translation and orthonormal
!!!
"
#
$$$
%
&−
−
=
!"
#$%
&=!
"
#$%
&⇒!
"
#$%
&=!
"
#$%
&
−
−
100''''''11
'1'
1
1
1
yyx
xyx
oyyoxx
M
MMpppp
computer graphics • transforms © 2009 fabio pellacini • 41
2D to 3D transformations
• adopt homogeneous formulation in 3d – points have 4 coordinates – use 4x4 matrices for transformations
• most concept generalize very easily – rotation much more complex
computer graphics • transforms © 2009 fabio pellacini • 42
affine transformations
!!!!
"
#
$$$$
%
&
=
1000100010001
z
y
x
ttt
Tttranslation
scale
!!!!
"
#
$$$$
%
&
=
1000000000000
z
y
x
ss
s
Ss
computer graphics • transforms © 2009 fabio pellacini • 43
affine transformations
!!!!
"
#
$$$$
%
& −
=
1000010000cossin00sincos
θθ
θθ
θzRrotation around z
computer graphics • transforms © 2009 fabio pellacini • 44
affine transformations
!!!!
"
#
$$$$
%
&
−=
10000cos0sin00100sin0cos
θθ
θθ
θyR
rotation around x
!!!!
"
#
$$$$
%
&−
=
10000cossin00sincos00001
θθ
θθθxR
rotation around y
computer graphics • transforms © 2009 fabio pellacini • 45
rotation around arbitrary axis
• in 2d, rotation are around a point – change coordinate frame (translation) – rotate around the origin – change coordinate frame back – simple geometric construction
• in 3d, they are around an axis – change coordinate frame (align z with axis) – rotate around z axis – change coordinate frame back – complex geometric construction
aaa −= TRTR θθ,
aaa FRFR θθ1
,−=
computer graphics • transforms © 2009 fabio pellacini • 46
rotation around arbitrary axis
• use a change of coordinate system – define new coordinate system with z’ parallel to axis and
origin on the axis
• build transform matrix as seen previously
!"
#$%
&=−
1000''''1 ozyx
F
computer graphics • transforms © 2009 fabio pellacini • 47
construct 3d frame from vectors
• given two non-parallel vectors a and b – i.e. a plane – set x, y parallel to a, b – x = a / |a|
z = x × b; z = z / |z| y = z × x
• given the vector a – set z parallel to a, choose arbitrary x, y – continue as above
computer graphics • transforms © 2009 fabio pellacini • 48
representing rotations
• 3 rotations around major axis – remember to choose order – simple but has quirks when combining rotations
• will use this for simplicity
• axis and angle – combinations of rotations can be represented this way – with more formalism become elegant and consistent
• quaternions
computer graphics • transforms © 2009 fabio pellacini • 49
transforming normals
• points and vectors works • tangents, i.e. differences of points, works too • normals works differently
– defined as orthogonal to the transformed surface – i.e. orthogonal to all tangents
computer graphics • transforms © 2009 fabio pellacini • 50
transforming normals
• by definition • after transform • for all t, we have • which gives
• normals are transformed by the inverse transpose
0==⋅ ntnt T
0)()( =nt XM T
0=nt XM TT
0)( 1 =− nt TTT MM
computer graphics • transforms © 2009 fabio pellacini • 51
transformation hierarchies
• often need to transform an object wrt another – e.g. the computer on the table – when the table moves, the computer moves
• naturally build a hierarchy of transformation – to transform the table, apply its transform – to transform the computer, apply the table and the computer
transform
computer graphics • transforms © 2009 fabio pellacini • 52
transformation hierarchies
• represented as a tree data structure – transformation nodes – object nodes - leaves
• walk the tree when drawing • very convenient representation for objects
– all objects can be defined in their simplest form – e.g. every sphere can be represented by a transformation
applied to the unit sphere
computer graphics • transforms © 2009 fabio pellacini • 53
transformation hierarchies
root
transform transform
sphere triangle transform sphere
triangle sphere
computer graphics • transforms © 2009 fabio pellacini • 54
implementing transformation hierarchies
• transformation function for each node – get the parent matrix – multiply the parent and current matrices – pass the combined matrix when calling children
• stack of transforms – push/pop when walking down/up – used by graphics libraries (OpenGL) – more flexible – generalized mechanism for all attributes
computer graphics • transforms © 2009 fabio pellacini • 55
raytracing and transformations
• transform the object – simple for triangles
• since they transforms to triangles
– but most objects require complex intersection tests • spheres do not transforms to spheres, but ellipsoids
• transform the ray – much more elegant – works on any surface – allow for much simpler intersection tests
• only worry about unit sphere, all others are transformed
computer graphics • transforms © 2009 fabio pellacini • 56
raytracing and transformations
• transforming rays – transform origin/direction as point/vector – note that direction is not normalized now
• i.e. ray parameter is not the distance
• intersect a transformed object – transform the ray by matrix inverse – intersect surface – transform hit point and normal by matrix