8/27/2009
MATRICES ADDITION
Given two matrices A and B if we want to add B to
A (that is form A+B) then if A is (nm), B must be
(nm), Otherwise, A+B is not defined.
2D TRANSFORMATIONS
The addition produces a result, C = A+B, with
elements:
Ci, j = Ai , j + Bi , j
Nihar Ranjan Roy
1 2 5 6 1 + 5 2 + 6 6 8
3 4 + 7 8 = 3 + 7 4 + 8 = 10 12
Nihar Ranjan Roy
MATRICES MULTIPLICATION (EXAMPL)
MATRICES MULTIPLICATION
Given two matrices A and B if we want to multiply
B by A (that is form AB) then if A is (nm), B must
be (mp), i.e., the number of columns in A must be
equal to the number of rows in B. Otherwise, AB is
not defined.
26+ 63+ 72=44
2 6 7 6 8 44 76
4 5 8 3 3 = 55 95
9 2 3 2 6 66 96
The multiplication produces
a result, C = AB, with
m
elements:
C = a b
i, j
6 8
2 6
4 5 3 3
2 6
ik kj
k =1
(Basically we multiply the first row of A with the
first column of B and put this in the c1,1 element of
C. And so on).
Nihar Ranjan Roy
Undefined!
2x2 x 3x2 2!=3
2x2 x 2x4 x 4x4 is allowed. Result is 2x4 matrix
Nihar Ranjan Roy
8/27/2009
MATRICES -- BASICS
TRANSFORMATION
Unlike scalar multiplication, AB BA
Matrix multiplication distributes over addition:
A(B+C) = AB + AC
Identity matrix for multiplication is defined as I.
The transpose of a matrix, A, is either denoted AT
or A is obtained by swapping the rows and
columns of A:
a1,1
A=
a2 ,1
a1, 2
a2, 2
a1,1
a1,3
A
'
=
a1, 2
a2,3
a1,3
Transformation is the process by which we can
change the shape , position and orientation of
an object
Basic
a2 ,1
a2, 2
a2, 3
Nihar Ranjan Roy
2D GEOMETRICAL TRANSFORMATIONS
Translate
Nihar Ranjan Roy
TYPES OF TRANSFORMATIONS
Geometric transformation when the object is moved
relative to a stationary coordinate system or
background it is called geometric transformation.
Shear
Coordinate Transformations in this transformation
the coordinate system is moved relative to the object
and the object is held stationary
Rotate Scale
Nihar Ranjan Roy
types of transformations are
Translation
Rotation
Scaling
Reflection
shearing
Nihar Ranjan Roy
8/27/2009
TRANSLATION
SCALING
We can specify how much bigger or smaller by means of a
scale factor
Translate the point p(x,y) to a new location which is given by
the vector v=txi+tyj;
To double the size of an object we use a scale factor of 2, to
half the size of an object we use a scale factor of 0.5
x' = x + t x
y' = y + t y
x' = s x x
In matrix format:
y' = s y y
x' x t x
y ' = y + t
y
If we define the translation matrix
P =P + T.
x' s x
y ' = 0
t x
T =
t y
, then we have
If we define
Nihar Ranjan Roy
ROTATION
sx 0
S sx , sy =
, then we have P =SP
0 sy
Nihar Ranjan Roy
10
MIRROR REFLECTION
Mirror reflection about x axis
Points can be rotated through an angle about the origin:
| OP ' |=| OP |= l
p`= M x ( p)
x ' 1 0 x
y ' = 0 1 X y
P(x,y)
x ' =| OP ' | cos( + ) = l cos( + )
= l cos cos l sin sin
= x cos y sin
y ' =| OP ' | sin( + ) = l sin( + )
= l cos sin + l sin cos
0 x
s y y
P(x,y)
x ' cos
y ' = sin
Mirror reflection about y axis
sin x
cos y
p`= M y ( p )
x ' 1 0 x
y ' = 0 1 X y
= x sin + y cos
P =RP
Nihar Ranjan Roy
11
Nihar Ranjan Roy
12
8/27/2009
SUMMERY
SHEARING TRANSFORMATION
The shear transformation cause the image to slant. X shear
maintains the y-coordinate but changes the x values which cause
the vertical lines tilt left to right
Shear in the x direction
SH
1
= 0
Simultaneous shearing
SH
a
1
0
xy
0
0
1
= b
Shear in the y direction
SH
a
1
0
Nihar Ranjan Roy
1
= b
0
1
0
0
0
0
0
Translate:
Scale:
Rotate:
Mirror
Shear
P = P+T
P = Ssx,sy(P)
P = R(P)
P = Mx(P) or P = My(P)
p=SHx(P) or p=SHx(P) or p=SHxy(P)
Multiplying versus adding matrix
Solution: Homogeneous Coordinates
Nihar Ranjan Roy
13
14
TRANSLATION AS HOMOGENEOUS
TRANSFORMATIONS
HOMOGENEOUS COORDINATES
For a given 2D coordinates (x, y), we introduce a third
dimension:
[x, y, 1]
In general, a homogeneous coordinates for a 2D point has
the form:
[wx, wy, w]
Now, redefine the translation by using homogeneous
coordinates:
Advantages
Similarly, we have:
matrix operations are simplified
Fractional calculations may be avoided example
tx x
ty y
1 1
0
1
0
P ' = Tv P
Scaling
x ' s x
y ' = 0
1 0
[1/2
1/3] in homogenous it can be represented as
[3 2 6]
P
Nihar Ranjan Roy
x ' 1
y ' = 0
1 0
x ' x t x
y ' = y + t
y
15
0
sy
0
Ssx,sy
Rotation
0 x
0 y
1 1
x ' cos
y ' = sin
1 0
Nihar Ranjan Roy
sin
cos
0
0 x
0 y
1 1
16
8/27/2009
ROTATION ABOUT AN ARBITRARY
POINT
Mirror Reflection about x-axis
p`= M x ( p)
& mirror reflection about y-axis
p`= M y ( p )
x' 1 0 0 x
y ' = 0 1 0 X y
z ' 0 0 1 z
x ' 1 0 0 x
y ' = 0 1 0 X y
z ' 0 0 1 z
R,p=Tv.R T-v
Simultaneous shearing
SH xy
1
= b
0
a
1
0
where
0
0
1
1 0 h
Tv = 0 1 k
0 0 1
17
Nihar Ranjan Roy
SCALING ABOUT AN ARBITRARY
POINT
1 0 h
Tv = 0 1 k
0 0 1
Ssx, sy
0
sy
0
Nihar Ranjan Roy
0
0
1
1 0 h
Tv = 0 1 k
0 0 1
Nihar Ranjan Roy
18
Let the line y=mx+c have a y intercept (0,c) and
Slope with x axis. The steps involved in this composite
Transformation are
1. Translate the intersection point A(0,c) to origin
2. Rotate by so that the line aligns with x axis
3. Mirror reflect about x axis
4. Rotate back by
5. Translate A back to point(0,c)
S(sx,sy),p=TV.Ssxsy .T-V
s x
= 0
0
cos sin 0
R = sin cos 0
0
0
1
REFLECTION ABOUT ANY LINE
Steps involved are
1. Translate the arbitrary point(h,k) to origin
2. Scale it with respect to origin
3. Translate back the arbitrary pt to original position
(inverse of step 1)
where
Let the arbitrary point be (h,k) and the point to be rotated
anti-clock wise is(x,y). The steps involved in transformation
are as follow
1. Translate (h,k) to origin
2. Rotate (x,y) by an angle
3. Translate the resulting point back to (h,k)
ML=TV .R .MX .R .T-V
1 0 h
Tv = 0 1 k
0 0 1
19
Nihar Ranjan Roy
20
8/27/2009
TRANSFORMATION ROUTINES
1 0
Tv = 0 1
0 0
1
Tv = 0
0
0
c
1
0 h
1 k
0 1
cos sin 0
cos sin 0
R = sin cos 0 R = sin cos 0
0
0
1
0
0
1
1 0 0
M x = 0 1 0
m
1
sin =
& cos =
0 0 1
m2 + 1
m2 + 1
finally
Slope m=tan() therefore
1 m 2
2
m +1
2m
ML = 2
m +1
0
2m
m2 + 1
m2 1
m2 + 1
0
2cm
m 2 + 1
2c
m 2 + 1
1
21
Nihar Ranjan Roy
IDENTITY-MATRIX(H)
ARGUMENT H is a transformation array of 3x3 elements
Local I,J variables for stepping through the H array
BEGIN
FOR I=0 TO 3 DO
FOR J=0 TO 3 DO
IF (I=J) THEN H[I,J]1
ELSE
H[I,J]0;
RETURN;
END
Nihar Ranjan Roy
22
TRANSFORMATION ROUTINES:-SCALE
MULTIPLY-IN-SCALE(SX,SY,H)
ARGUMENTS sx and sy scaling factor
H an identity matrix
LOCAL
I,J to iterate through matrix
BEGIN
FOR I=1 TO 3 DO
BEGIN
H[I,1]H[I,1]*SX
S sx , sy
H[I,2]H[I,2]*SY
END
RETURN
END
Nihar Ranjan Roy
Similarly write transformation routines for
Translation
Rotation
sx 0 0
= 0 sy 0
0 0 1
23
Nihar Ranjan Roy
24
8/27/2009
DISPLAY PROCEDURE
PROBLEM
The display procedure call involves
1. Saving the over all transformation matrix
2. Multiply the overall transformation matrix on the
left by the transformation in the call to form a new
overall transformation matrix
3. Transferring the control to the display procedure
Reflect the diamond shaped polygon whose vertices
are A(-1,0) B(0,-2) C(0,1) and D(0,2) about
1. Horizontal line y=2
2. Line y=x+2
A return from the display procedure involves the
following
1. Restoring the overall transformation matrix from
the saved value
2. Returning the control to the calling program
Nihar Ranjan Roy
25
Nihar Ranjan Roy
26
1) Since the line is parallel to x-axis we donot need to rotate the
polygon
A(-1,4)
2)
ML=TV MX T-V
B(0,6) C(1,4) D(0,2)
1 m 2
2
m +1
2m
ML = 2
m +1
0
A(-2,1) B(-4,2)
2m
m2 +1
m2 1
m2 +1
0
C(-2,3)
2cm
m 2 + 1 0 1 2
2c
= 1 0 2
m 2 + 1
1 0 0 1
D(0,2)
Nihar Ranjan Roy
27