2D 3D Transformations
2D 3D Transformations
2D 3D Transformations
1. Translation
This allows you to move an object in the x-y plane. This is accomplished by
adding a translation distance to the x and y coordinates of the original vertex.
B B1
(x , y)
X1=x+Tx
Y1=y+Ty
1
In matrix notation
X1 x Tx x+Tx
Y1 = y + Ty = y + Ty
Alternatively
x1 1 0 Tx x
y1 = 0 1 Ty y
1 0 0 1 1
2
For 3D translation
X1 1 0 0 Tx x
Y1 = 0 1 0 Ty y
Z1 0 0 1 Tz z
1 0 0 0 1 1
3
2. SCALING
The scale function allows us to change the size of an object. Each of the vertex’s original
coordinates are multiplied by a scaling factor.
X1 = x.Sx
Y1 = y.Sy
A scaling constant greater than one indicates an expansion of length , and less than one,
compression of length.
After scaling transformation is performed the new object is located at different position relative
to the origin.
Matrix notation
X1 = Sx 0 x
Y1 0 Sy y
For Sx = 2, Sy =2
2 Sx =2
Y2 1 Sy= 1/2
1 3 x 1 2 4
4
Using 3X3 matrix, 2D scaling matrix is:
x1 Sx 0 0 x
y1 =
0 Sy 0 y
1 0 0 1 1
x1 Sx 0 0 0 x
y1 =
0 Sy 0 0 y
z1 0 0 Sz 0 z
1 0 0 0 1 1
5
Consider a point (x,y) rotated about origin as shown below;
where is the angle of rotation , r is the radial vector , is the angle made by the radii vector
with +ve x axis.
It can be written as
x= rcos
y=rsin
Similarly, x1 = r cos ( + )
y1 = r sin ( + )
Expanding
= x cos - y sin
Similarly
= xsin + ycos
6
Therefore, the general representation of equations of rotation
If rotation is effected or carried out about any point (XR, YR) then the equation of rotation can be
proved as
X1
= cos - sin x
Y1 sin cos y
Or using 3X 3 Matrix :
X1 cos -sin 0 x
Y1 = sin cos 0 y
1 0 0 1 1
7
In 3D (anticlockwise)
X1 cos -sin 0 0 x
Y1 Sin cos 0 0 y
Z1 0 0 0 z
1 0 0 0 1 1
Or using 3X 3 Matrix :
X1 cos sin 0 x
Y1 = -sin cos 0 y
1 0 0 1 1
8
4. REFLECTION
By using this routine, it is possible to obtain mirror image of an object.
Reflection is always carried out about an axis called the axis of reflection.
If the axis of reflection is the x-axis then the x- coordinates of the point remains unchanged while
the y-coordinate flips (changes sign).
Similarly when the axis of reflection is the y-axis the y-coordinate of the reflection remains the
same while the x coordinate changes its sign.
y P(x,y)
x-axis
P1(x1,-y1)
Reflection Matrix
X1 x 1 0 x
Y1 = -y = 0 -1 y
Ie Mx = 1 0
0 -1
9
Using a 3X 3 Matrix
Mx = 1 0 0
0 -1 0
0 0 1
That is:
x1 1 0 0 x
y1 = 0 -1 0 y
1 0 0 1 1
(-x,y)p1 (x,y).p
Reflection matrix
x1 = x -1 0 = -x
y1 y 0 1 y
10
Or using 3X3 Matrix:
x1 = -1 0 0 x
y1 0 1 0 y
1 0 0 1 1
Reflection matrix when the axis of reflection is the line passing through the
origin
y
y=mx
The equation of the line passing through origin is y = mx; where m is the slope
(m=tan )
11
The following steps should be taken:
1. Rotate the line that is the axis of reflection y=mx in clock wise direction by angle
=tan-1 (m) to align it with x-axis. Rotation matrix is given by
[A1] =
Cos(- -sin(- ) 0
sin(- ) cos( ) 0
0 0 1
Cos( sin( ) 0
= -sin( ) cos( ) 0
0 0 1
2. Reflection about x-axis obtained let [A2] represent the reflection matrix then.
[A2 = 1 0 0
0 -1 0
0 0 1
12
3. Now the line is rotated by angle in counter-clockwise direction so that original
position of line is restored
-sin cos 0
0 0 1
[R] = [A3]x[A2]x[A1]
13
Reflection matrix when Axis of Reflection is a line y= mx+c
(equation of a line not passing through origin)
The resultant matrix is obtained by concatenating the above five transformation matrices.
14
5. Shearing
A shearing Transformation produces distortion of an object or an image. There are
two types of shears, refer figs.
1) X-direction shear
2) Y-direction shear
In x-direction sheer, the x-coordinate will change while the y-coordinate will
remain same
y y
if shx is the shearing factor in x director then the basic equation are
x1 = x +shx y
y1 =y
In the y-direction shear, the y-coordinate will change while the x-coordinate will
remain the same. If shy is the shearing factor in the y-direction then basic equations
are:
x1 = x
y1 = y +x . xshy
15
Shear matrices
x1 1 shx x
y1 = 0 1 y
x1 = 1 0 x
y1 shy 1 y
x1 = 1 shx x
y1 shy 1 y
x1 1 shx 0 x
y1 = shy 1 0 y
1 0 0 1 1
16
Worked Examples
1. A triangle is defined in two dimensions by its vertices (1,2), (1,3) and (2,2) .
Perform the following transformations on this triangle
Solutions
a) The general transformation matrix for translation is given as
1 0 Tx
0 1 Ty
0 0 1
0 1 3
0 0 1
17
The transferred Image of the vertices of the triangle can be found out as
1 0 2 1 1 2 = 3 3 4
0 1 3 2 3 2 5 6 5
0j 0 1 1 1 1 1 1 1
(1, 2) (3,5)
(1, 3) (3,6)
(2,2) (4,5)
Sx 0 0
0 Sy 0
0 0 1
0 1.5 0
0 0 1
18
The transferred Image of vertices of triangle and scaling can be found out as:
0 1.5 0 2 3 2 = 3 4.5 3
0 0 1 1 1 1 1 1 1
(1, 2) (1.5, 3)
(2, 2) (3, 3)
cos sin 0
-sin cos 0
0 0 1
19
The T.M for rotation can be written as
0.707 0.707 0
-0.707 0.707 0
0 0 1
0.707 0.707 0 1 1 2
-0.707 0.707 0 2 3 2
0 0 1 1 1 1
= 0.707 1.414 0
1 1 1
(2, 2) ( 2.83 , 0 )
20
Find the reflection of the point (3,11) about a line y=3x+4
Solution
The transformation matrix for reflection about a line y=3x+4 can be obtained by using a
concatenation process as follows
x=3x+4
=tan-1 (3)=71.560
(0,4)
The line (y=3x+4) is translated by 4 units in negative y-direction so that it posse through the
origin
[A]= 1 0 0
0 1 -4
0 0 1
The line (y=3x+4)is then rotated in clockwise direction by an angle 71 so that it coincides with
x-axis.
21
Let [B]represent the T.M. for this rotation.
-sin(-71.56) cos(-71.56) 0
0 0 1
- Getting the reflection above the line, which coincides with x-axis
[C] =
1 0 0
0 -1 0
0 0 1
Rotating the line by an angle 71.560 Anti -Clockwise direction, let [D] represent
the T.M for this rotation
sin(71.56) cos(71.56) 0
0 0 1
22
= 0.316 - 0.948 0
0.948 0.316 0
0 0 1
Translating the line by 4 units in position y-direction, so that original position line is
restored
[E]= 1 0 0
0 1 4
0 0 1
[R] =
23
Vertex = 3
11 =
(3,11) [?, ? ]
24