chi-cheng lin, winona state university cs430 computer graphics transformations of objects – 2d...
TRANSCRIPT
Chi-Cheng Lin, Winona State University
CS430 Computer Graphics
Transformations of Objects – 2D Part I
2
Topics
Matrix Prelim Introduction Fundamental Transformations Affine Transformations More Affine Transformations Inverse of Affine Transformations Composition of Affine
Transformations
3
Matrix Prelim Matrix: rectangle array of numbers A: nm matrix n rows, m columns
A vector in nD-space an n1 matrix
nmn
m
aa
a
aaa
1
21
11211
.:
.:
.
...
1
21
11
na
a
a
:
:
4
Matrix Multiplication
A: nm matrix B: mp matrixC = A B : np matrix, where
Ai =i th row vector of A
Bj =j th column vector of B
cij = Ai • Bj
A B = B A ?? A (B + C )= A B + A C ??
m
ssjisij bac
1
5
Identity Matrix
Identity matrix I
otherwise,
,
.:
.:
.
...
I
0
1
10
1
10
001
jiij
6
Determinant of Matrix Determinant of a 22 matrix A:
Determinant of an nn matrix A:
where A1i = determinant of an (n-1)(n-1) matrix obtained by deleting the first row and i th column from A
Find the determinant of a 33 matrix! (p.824)
n
jj
jj Aa
11
11 1)(detA
bcaddb
ca
AA det
7
Transpose and Inverse of Matrix
Transpose of an nm matrix A is an mn matrix B B = A T, i.e., bij = aji Transpose of an n1 column vector is
a 1n row vector Inverse of an nn matrix A is an
nn matrix B B = A-1
A B = B A = I
8
Introduction
Transformation: cornerstone of CG Change the position, size,
orientation of objects We will focus on linear
transformation Like other graphics systems,
transformation is also central to OpenGL
9
OpenGL Graphics Pipeline OpenGL pipeline
ExampleglBegin(GL_LINES);
glVertex3f(…) // send P1 through the pipelineglVertex3f(…) // send P2 through the pipelineglVertex3f(…) // send P3 through the pipeline
glEnd();
CT Process& display
P1, P2, … Q1, Q2, …
P1
P2 Q1
Q2
10
Transforming Points and Objects
Transformation alters each point P in space into a new point Q by means of formula or algorithmP is mapped to QQ is the image of P under the mapping T
Fundamental transformationsTranslateScaleRotate
11
Fundamental Transformations - Translation
TranslationChange the position of an object(Qx, Qy) = (Px + dx, Py + dy)
orQ = P + T, where T = (dx, dy)
P2
P1
Q1
dx
dy x
yQ2
12
Translation Example
Example
dx= 3dy=-4
13
Fundamental Transformations - Scaling Scaling
Change the size of an object(Qx, Qy) = (Sx Px, Sy Py)
or or
Actually it is scaling about the origin
y
x
y
x
y
x
P
P
S
S
Q
Q
0
0
Sx=3
Sy=2
x
y
y
x
y
x
P
P
Q
QS
Sx=3
Sy=2
xX
14
Scaling Example
Example
Sx=1/2Sy=1/4
15
Fundamental Transformations - Rotation
RotationChange the orientation of an object(Qx, Qy) = (Pxcos -Pysin, Pxsin +
Pycos)
or or
Derivation of rotation mapping?
y
x
y
x
P
P
Q
Q
cossin
sin-cos
P
Q
x
y
y
x
y
x
P
P
Q
QR
rr
16
Fundamental Transformation -Rotation
Rotation (cont’d)Rotation is performed about the
origin
x
y
17
Rotation Example
Example
= 45o
18
Affine Transformations Questions
How do we scale/rotate about any point?How do we combine transformations?
Problem of composing transformationsTranslation: Q = T + P additionScaling: Q = S P multiplicationRotation: Q = R P multiplication
Solution: homogeneous coordinatesRepresent a 2D point (x, y) as (x, y, 1) A vector (a, b) = (a, b, 0)
19
Affine Transformations
Coordinates of point Q are linear combinations of those of point P:
Translation, scaling, and rotation are affine transformations (so are their combinations)
11232221
131211
mPmPm
mPmPm
Q
Q
yx
yx
y
x
11001232221
131211
y
x
y
x
P
P
mmm
mmm
Q
Q
20
Affine Transformations Translation, scaling, and rotation are affine
transformations Succession of affine transformation is an
affine transformation Affine transformation from vector V to
vector W :
The third row of the transformation matrix is always (0, 0, 1)
01000232221
131211
y
x
y
x
V
V
mmm
mmm
W
W
21
Fundamental Transformations Revisit
Translation(Qx, Qy) = (Px + dx, Py + dy)
1100
10
01
1y
x
y
x
y
x
P
P
d
d
Q
Q
100
10
01
y
x
yxyx d
d
ddPddQ ),(,),( T T
22
Fundamental Transformations Revisit
Scaling(Qx, Qy) = (Sx Px, Sy Py)
1100
00
00
1y
x
y
x
y
x
P
P
S
S
Q
Q
100
00
00
x
x
yxyx S
S
SSPSSQ ),(,),( S S
23
Fundamental Transformations Revisit
Rotation(Qx, Qy) = (Pxcos -Pysin, Pxsin +
Pycos)
1100
0
0
1y
x
y
x
P
P
Q
Q
cossin
sincos
100
0
0
cossin
sincos
)(,)( R R PQ
24
More Affine Transformations - Reflection
Reflection – special case of scalingSx < 0 reflection about the y-axis
Sy < 0 reflection about the x-axis
Sx=3
Sy=2
y
Sx=-0.5
Sy=1
Sx=3
Sy=-2
x
25
More Affine Transformations - Reflection
Pure reflectionEach of the scale factors is either +1 or –1Examples
T(Px, Py) = (-Px, Py) flip horizontally about y-axis
T(Px, Py) = (Px, -Py) flip vertically about x-axis
T(Px, Py) = (-Px, -Py) ?
Uniform scalingSx = Sy = S, where |S| is magnification factor
Differential scalingSx Sy
26
More Affine Transformations - Shearing ShearX
x-coordinate is translated by an amount that increases linearly with y
y-coordinate is unaffectedCan be used to make italic
letters out of regular ones(Qx, Qy) = (Px + hPy, Py)
PhQP
Ph
Q
Q
xy
x
y
x
Sh )(
1100
010
01
1
27
More Affine Transformations - Shearing
ShearYy-coordinate is translated by an amount
that increases linearly with xx-coordinate is unaffected(Qx, Qy) = (Px, gPx + Py)
PgQP
P
gQ
Q
yy
x
y
x
Sh )(
1100
01
001
1
28
Inverse of Affine Transformations If Q =MP, then P =M–1Q, where M–1 is the
inverse of M (i.e., M M–1 = I )
where det M = m11m22 - m12m21
Inverse of an affine transformation is an affine transformation!
100232221
131211
mmm
mmm
M
100
1132111231121
2312221312221 )(
)(
detmmmmmm
mmmmmm
MM
29
Inverse of Affine Transformations
Translation: T -1(dx, dy) = T(-dx, -dy)
Scaling: S -1(Sx, Sy) = S(1/Sx, 1/Sy) Rotation: R -1() = R(-) ShearX: ShX -1(h) = ShX (-h)
ShearY: Shy -1(g) = Shy(-g)
Verify that those matrices are correct If M = I, what transformation is it?
30
Composition of Affine Transformations
Composing (concatenating) transformationsProcess of applying several transformations in
succession to form one overall transformation Composition of affine transformations is
affine If a sequence of transformations are
represented by matrices M1, M2, …, Mn, then a point P is transformed to a point Q = (Mn((M2(M1 P)))
= (Mn M2M1)P
31
Composition of Affine Transformations
Example: Build a transformation matrix thatRotates 45 degreesScales in x by 1.5 and in y by –2Translates by (3, 5)Find the transformed point of P = (1, 2)Solution:
Q = M P = (1.94, 0.758, 1)
100
541414141
3061061
100
04545
04545
100
020
0051
100
510
301
..
..
)cos()sin(
)sin()cos(.
M
32
Applications of Composition
Rotate about an arbitrary point (x, y)Translate by (-x, -y)Rotate about the origin through angle
Translate by (x, y)Transformation matrix
M = T(x, y)R()T(-x, -y)
100
yyx
xyx
)cos()sin()cos()sin(
)sin()cos()sin()cos(
12
3
33
Applications of Composition
Scale about an arbitrary point (x, y)Translate by (-x, -y)Scale in x by Sx and in y by Sy Translate by (x, y) Transformation matrix M
= T(x, y)S(Sx, Sy)T(-x, -y) = ??
Window-to-viewport transformation is also a good example of composition of affine transformations (why?)
34
Applications of Composition
Reflection about an axis of reflection that makes an angel of with the x axisRotate by -Reflect about x-axis
(i.e., scale in x by 1 and in y by –1)
Rotate by
35
Applications of Composition Reflection about an axis of
reflection that makes an angel of with the x axisTranslation matrix M
= R()S(1, -1)R(-)Let c = cos(-) and s = sin(-),
100
022
022
100
02
02
100
0
0
100
010
001
100
0
022
22
)cos()sin(
)sin()cos(
cscs
cssc
cs
sc
cs
sc
M
Check it out!