Title: Part III Geometric Transformations
1Part III Geometric Transformations
2Vector and Dot Product
- Vector addition
- or (a b)(c d)(ac bd)
- We will use column vectors and row vectors
interchangeably. - Dot product v1v2 (x1 y1)(x2 y2) x1x2
y1y2 - Vector length
- 2nd def. of dot product v1v2 v1v2cos?
- When v1 1, v1v2 is the length of the
projection of v2 onto v1 .
v2
v1
v2cos?
3Vector and Dot Product (contd)
- Vector normalization makes a unit vector (of
length 1) v/v - e.g. (3 4) ? (3/5 4/5)
- If vivj is 0, vi vj are orthogonal/perpendicul
ar. - If vivj is positive, vi is in the same
half-plane defined by vj. - Equivalently, vj is in the same half-plane
defined by vi. - If vivj is negative, vi vj are in different
half-planes defined by vj (or vi). -
- ? If vi is a unit vector, the dot product of vi
vi are 1. - e.g.
- ? So far 2D, but the same for 3D
- e.g. v1v2(x1 y1 z1)(x2 y2 z2)x1x2y1y2z1 z2
y
? (0 2) (5 0) 05200 ? (2 2) (5 0)
252010 gt 0 ? (-3 2) (5 0) -3520-15 lt
0
(0 2)
(2 2)
(-3 2)
(5 0)
x
4An Example Use of Dot Product
- Lets derive the shortest distance from a point
(p q r) to a plane axbyczd0. - A plane P is typically defined by its normal (a b
c) and a point (l m n) on P. - Given a normal (a b c), a plane is set to
axbyczd0, where d is unknown. - Then, for axbyczd0, albmcnd0 and
therefore d -al-bm-cn. - Normalize (a b c)
- Connect (p q r) and (l m n) to make a vector
C(p-l q-m r-n). - Note that NC is the length of the projection of
C onto N because N 1, and therefore NC is
the distance from a point (p q r) to the plane. -
(p q r)
C
(a b c)
(l m n)
axbyczd0
5Cross Product
- ? v1 x v2 ( y1z2 - z1y2 z1x2 - x1z2
x1y2 - y1x2 ) - ? v1 x v2 u v1v2 sin? where u is a unit
vector perpendicular to both v1 v2 based on the
right hand rule.
?
?
?
v2
u
v1
6Coordinate System
- A set of vectors vis is linearly independent if
a1v1a2v2 .. anvn0 (zero vector) only when
every ai0. - Any set of n linearly independent vectors in an
n-dimensional vector space V is a basis. - A basis v1, v2, .. vn is an orthonormal basis
if vivj 0 if i? j and vivj 1 if ij. - An origin and a basis constitute a frame or a
coordinate system.
7Matrix
- column and row
-
- identity matrix
- transpose
- matrix composition
- M-1 is an inverse matrix of M if MM-1I.
3x2
2x3
3x3
8Translation
- A transformation is a function that maps a
point/vector into another point/vector. - For now, we will discuss the basic 4 types of
transformations - translation, scaling, rotation, and shearing.
- Translation
( x?, y?)
dy
(x, y)
dx
9Scaling
- Scaling is done about the origin.
- Scale x by sx along x-axis x? sxx Scale y
by sy along y-axis y? syy - The above example is called a uniform scaling
where sx sy. - If sx ? sy, non-uniform scaling.
- If sx or sy lt 1, objects are moved closer to the
origin. - If sx or sy gt 1, objects are moved farther from
the origin.
10Rotation
- Rotation by an angle ? about the origin.
- The distance from P to the origin is r.
- Angles are measured counter-clockwise (CCW).
- x r cos?
- y r sin?
- x? r cos(??) r cos? cos? - r sin? sin?
xcos? - ysin? - y? r sin(??) r cos? sin? r sin? cos?
xsin? ycos? - For CW, use cos(-?)cos? and sin(-?)-sin?.
P? (x?, y?)
r
r
P(x, y)
r
11Shearing
- Shearing along x
- Used for italic font design (whereas scaling is
for font size). -
y? y (unaffected) x? x ay (in the example,
a ? 0.5)
- Similarly, shearing along y
-
y
x
12Affine Transformation
- A mapping T V?V (V is a vector space) is a
linear transformation if, for all scalars a and
all vectors x,y, it satisfies the following
conditions - T(ax)aT(x)
- T(xy)T(x)T(y)
- Linear transformations include identity
mapping(I), rotation, scaling, shearing,
reflection, etc. - A translation in a vector space V is a mapping
that associates to each vector x of V another
vector yx? where ? is a fixed vector. - Translations are not linear transformations.
- A transformation T in a vector space V is affine
if there exists a linear transformation T' such
that, for all x,y of V, T(x)-T(y)T'(x-y). - Both translations linear transformations are
affine transformations. - Affine transformations preserve lines
parallelism, but not necessarily their lengths
and angles, and are represented by the 3x4
matrix. Compare affine transformations with
(perspective) projection transformation. (later!)
13Homogeneous Coordinates
- Observe that rotation, scaling shearing are
done by matrix composition while translation is
by vector addition. Can we treat them
uniformly? - YES!! Use Homogeneous Coordinates.
- Practical motivations for Homogeneous
Coordinates. - We can treat linear transformations (rotation,
scaling, shearing, etc.) translation uniformly. - We can deal with projections (later!).
- A point (x, y) in Cartesian Coordinates is
represented as (wx, wy, w) in Homogeneous
Coordinates where w can be any non-zero value. - e.g. (2 3) ? (2 3 1) (4 6 2) (5 7.5
2.5) ... but, typically w1. - For a vector, w0.
- e.g. (2 3 0) is a vector whereas (2 3 1) is
a point. - e.g. (1 3 0) is a vector connecting two points
(4 5 1) and (5 8 1).
14Transformations in Homogeneous Coordinates
- translation (x? xdx, y? ydy)
- Note that all transformations are done by matrix
composition thanks to homogeneous coordinates. - Transformations which do not alter a bodys shape
are called rigid-body transformations and consist
of rotations translations.
15Rotation about An Arbitrary Point
- How to rotate about an arbitrary point p(x, y),
not about the origin?
q?(a?,b?)
q?
?
q???
q???
q(a,b)
q
?
q??
q??
p
p (x,y)
p?O
p?O
translate q by -p rotate by ?
back-translate
3x3 3x3
3x3
translate translate rotate translate, rotate
back-translate
- Thanks to Homogeneous Coordinates, three
transformations can be combined into a single 3x3
matrix.
16Inverse Transformation
- Note that the first and last translations are
inverses of each other. - Such an inverse transformation is represented as
an inverse matrix, but can be obtained pretty
easily if its geometry is considered. - Using your knowledge in linear algebra, show that
the above holds.
q?
q???
q???
q
?
q??
q??
p
p?O
p?O
translate q by -p rotate by ?
back-translate
inverse transformation
17Associativity Commutativity
- Matrix multiplication is associative.
- So is transformation composition.
- ABC (AB)C A(BC)
- In contrast, matrix multiplication is not
commutative in general. - Neither is transformation composition.
- e.g. combination of rotation (by 90CCW)
translation along y - rotation first translation first
183D Translation and Scaling
- First of all, Homogeneous Coordinate for 3D
- (x y z) ? (wx wy wz w) e.g (x y z 1)
- Translation
- Scaling
193D Rotation
- For 3D rotation, we need an axis of rotation.
- Also, by convention, positive angles are for CCW.
- Recall that, in 2D, x? xcos? - ysin? and y?
xsin? ycos?. -
- Add z-axis and make z? z. Then, its 3D
rotation about the z-axis.
y
(x,y)
(x?, y?)
x
y
(x,y,0)
(x?, y?,0)
x
z
Rz(?)
203D Rotation (contd)
- Rotation about x-axis
- Note that the coordinate system follows the right
hand rule. - Lets do cyclic permutation of the 3 axes, where
the right hand rule holds. - Note that rotation about x-axis is the same as
rotation about the old z-axis except the
permutation. - For rotation about y-axis, do one more
permutation! - 3D shearing will be discussed when we deal with
viewing.
x?y?z?x
y
z
y'
y
z'
z
x'
x
213D Rotation about An Arbitrary Rotation Axis
y
by ?
x
z
Step1 Translate such that the rotation axis
passes through the origin.
Step2 Rotate such that the rotation axis
coincides with a coordinate axis.
Step3 Rotate by ?
Step4 Inverse rotation. (Inverse of Step2)
Step5 Inverse translation. (Inverse of Step1)
223D Rotation Step1
- Rotation axis is typically defined by 2 end
points p1 and p2 (or a point p and a vector v) ?
Move p1(x1 y1 z1) to the origin.
233D Rotation Step2
- Why Step2? Because available rotations are all
about coordinate axes. - However, we also cannot directly perform Step2.
So, divide Step2 into two substeps Step2-1 and
Step2-2. - Consider the unit vector u along the rotation
axis.
Step2-1 Rotation about x onto xz-plane
Step2-2 Rotation about y onto yz-plane
p2?(x2? y2? z2?)
p2 (x2 y2 z2)
unit vector u
p1?(x1? y1? z1?)
p1 (x1 y1 z1)
243D Rotation Step2-1
- In Step2-1, how much angle to rotate? It is
convenient if we consider the projection of u
onto yz-plane, u?. - Rotation about x is represented by
- Note that a itself is not important but we need
sina cosa. - How can we compute sina cosa?
u(a b c)
u? (0 b c)
uz (0 0 1)
253D Rotation Step2-1 (contd)
- Recall the definitions for dot product and cross
product.
263D Rotation Step2-2
- Rotation about y
- Rotation about y is represented by
- Note that ? itself is not important but we need
sin? cos?. - How to compute sin? cos?? Same as in Step2-1!
? Rotation about x-axis leaves us x-component
unchanged, i.e. a. ? u?? is on xz-plane, and so
y-component is 0. ? u?? should be a unit vector,
and so z-component is .
?
273D Rotation Step2-2 (contd)
- Recall the definitions for dot product and cross
product. - u??? uz (a 0 d) ? (0 0 1) d
- u??uzcos? cos? ? d cos?
- u?? x uz (a 0 d) x (0 0 1) (0 -a 0)
- uy u??uzsin? (0 sin? 0)
? -a sin?
?
283D Rotation Steps 3, 4 and 5
- After Step1 and Step2, we are in the following
situation. - So, Step3 is simply
- Step4 an inverse of the matrix computed at Step2
- Step5 an inverse of the matrix computed at Step1
- R(?) is a single 4x4 matrix. All done!!!!
29Orthogonal Matrix
- A lot of matrix multiplications in R(?) lead to
- Inefficiency
- error accumulation
- There is a less intuitive but better method -
Use orthogonal matrix. - 2 columns vi vj are orthonormal if
- i.e. ? each column is a unit vector, and
- ? any two different columns are
orthogonal. - Orthogonal matrix a matrix with orthonormal
columns. - e.g.
30Orthogonal Matrix (contd)
- A matrix Q is orthogonal ? QTQ I (identity
matrix) - In other words, QT Q-1, i.e. for orthogonal
matrices, the transpose is the inverse. - Then, QQT I
- ? (QT)TQT I
- ? QT is an orthogonal matrix if Q is an
orthogonal matrix. -
0
...
0
0
1
0
...
0
1
0
...
0
...
1
0
0
...
...
...
...
...
...
1
0
0
0
31Orthogonal Matrix (contd)
- We can decompose QTQ I in the following way.
- An orthogonal matrix transforms its rows into
coordinate axes. - Rotation is a special orthogonal matrix. Lets
see.
0
...
0
0
1
orthogonal matrix
0
...
0
1
0
...
0
...
1
0
0
...
...
...
...
...
...
1
0
0
0
nxn nxn
nxn
0
1
0
0
0
1
0
0
0
...
...
...
...
...
...
1
0
0
nxn nx1 nx1 nxn
nx1 nx1 nxn
nx1 nx1
32Orthogonal Matrix Rotation
- Suppose that you have the following two
orthonormal vectors. - Make an orthogonal matrix M with v1 and v2 as the
1st and 2nd rows respectively. - Then, M transforms v1 and v2 into ux and uy,
respectively. - Rotation is a special orthogonal matrix whose
determinant is 1. For example, an orthogonal
matrix with v2 and v1 as the 1st and 2nd rows is
not a rotation. Every rotation is an orthogonal
matrix. - In summary, we found that
- a rotation can be generated as an orthogonal
matrix, and - for a rotation, its inverse is the transpose.
v1
v2
45º
v2
v1
M
M
333D Orthogonal Matrix
uy
- Same in 3D
-
-
- R transforms v1, v2 and v3 into ux, uy and uz,
respectively.
v1
v2
an orthogonal matrix
v3
ux
34Application of Orthogonal Matrix
- Recall that, after Step1, our goal was to rotate
u into uz. -
- For this purpose, lets make an orthogonal matrix
whose 3rd row is u.
z
35Application of Orthogonal Matrix (contd)
y
u v3
uy
v2
x
ux
v1
uz
z
- Recall that R(?)T-1Rx-1(?)Ry-1(?)Rz(?)Ry(?)Rx(?)T
- The orthogonal matrix R replaces Ry(?)Rx(?)!
- Maybe more importantly, RT replaces
Rx-1(?)Ry-1(?)? - This alleviates error accumulation makes the
overall transformation efficient.
36Structure-deforming Transformations
- At the opposite end of rigid-body transformations
are structure-deforming transformations such as
tapering.
- Note that all y- z-coordinates of the object
are unchanged. - However, x-coordinates are scaled(reduced) along
the z-axis.