Sie sind auf Seite 1von 9

2D TRANSFORMATIONS

INTRODUCTION
Transformation is repositioning or resizing an object. Transformation includes any kind
of restructuring of an object which can be positioning or rotating or scaling of the object.

BASIC TRANSFORMATIONS

There are three types of basic transformations in 2D.


A) Translation
B) Rotation
C) Scaling
A) Translation
Translation refers to changing the position of an object along a straight-line path. This
transformation is applied to an object by repositioning it along a straight path from one
coordinate (or point) to another coordinate (or point). We can translate a 2D point by
adding translation distance, tx and ty, to the original coordinate position (x, y) to move the
point to a new position (x/,y/).
x/=x+ tx, y/= y+ ty ---------------------------------------------- 5.1
The translation distance pair (tx, ty) is called a translation vector or shift vector.
Equation 5.1 can be represented in matrix format as follows
P/=P+T ------------------------- 5.1(a)
Where P, P/, T are matrices of column vectors to represent initial coordinate positions,
final coordinate positions and the translation vector respectively
and defined as follows.
/ /
P/(x/, y/ )
P= x P= x
P

y y/

and T= tx P (x, y )
ty
B) Rotation Fig-5.1
Rotation refers to changing the position of an object along a Translating a point
circular path. This transformation is applied to an object by from point P to
repositioning it along a circular path on xy-plane. To get point P/.
rotation, we specify a rotation angle θ and the position (xr, yr) of the rotation point (or
pivot point) about which the object is to be rotated. Positive value of rotation angle
defines anti-clockwise (or counterclockwise) rotations about the rotation (or pivot) point
and negative value of rotation angle defines clockwise rotation. The rotation can also be
treated as a rotation about a rotation axis which is perpendicular to xy-plane and passes
through the pivot point.
If we consider the position of pivot point, there will be following two cases
Case-I Pivot point is at the coordinate origin
Consider Fig-5.2. Here origin O is the pivot point. r is the distance between O and B(x,
y).Now OB line rotates an angle θ anticlockwise and the point B moves to point B/ whose
coordinate is (x/,y/). Using standard trigonometric identities, we can express the
transformation equation for rotating a point at position (x, y) through an angle θ about the
origin as:
x/=xcosθ – ysinθ, y/=xsinθ + ycosθ ------------------------ 5.2
Equation 5.2 can be represented in matrix format, with the column vector representations
5.1(a) for coordinate positions, as follows
P/=R . P -------------------------- 5.2(a)
Where the rotation matrix R is

R= cosθ -sinθ

sinθ cosθ

B/(x/, y/)

B/(x/, y/) r r B(x, y)


r θ
B(x, y) φ
r A(xr, yr)
φ
O (0, 0) O (0, 0)
Fig-5.2 Fig-5.3
Rotating a point from point B(x, y) to position B/(x/, y/) through an angle θ about rotation
point O (0, 0) and A (xr, yr) respectively.

Case-II Arbitrary pivot point


Consider Fig-5.3. Here A is the pivot point. r is the distance between O and B(x, y).Now
OB line rotates an angle θ anticlockwise and the point B moves to point B/ (x/,y/). Using
standard trigonometric identities, we can express the transformation equation for rotating
a point at position (x, y) through an angle θ about any arbitrary point A(xr, yr) as:
x/= xr +(x- xr ) cosθ – (y- yr ) sinθ, y/= yr +(x- xr ) cosθ + (y- yr ) sinθ ---- 5.3
These general rotation equations differ from equations 5.2 by the inclusion of additive
terms, as well as the multiplicative factors on the coordinate values.

Line OB in fig 5.2 and line AB in fig 5.3 makes an angle φ with the X-axis.
C) Scaling
A scaling transformation alters the size of an object. This operation can be carried out for
polygons by multiplying the coordinate values (x, y) of each vertex by scaling factors sx
and sy to produce the transformed coordinates(x/, y/)
x/=x . sx, y/=y . sy ----------------------------------- 5.4
Scaling factors sx scales objects in the x-direction, while sy scales in the y-direction. The
transformation equations 5.4 can also be represented in the matrix form as follows:
x/ = sx 0 x
y/ 0 sy y
or
P/ = S . P ------------------------------- 5.5
Where S is the 2 X 2 scaling matrix.
Any positive value can be assigned to the scaling factors sx and sy. Values less than 1
reduce the size of the object and value greater than 1 produce an enlargement. Value 1 for
sx and sy leaves the size of object unchanged. If the value of sx and sy be same, a uniform
scaling is produced.

O(0, 0) O(0, 0)
Fig-5.4 Fig-5.5
/ / /
Turning a rectangle OABC into another rectangle OA B C (fig-5.4) with scaling factors
sx=2 and sy=2 and OAB/C/(fig-5.5) with scaling factors sx=2 and sy=1.

OTHER TRANSFORMATIONS

Translation, Rotation, Scaling, these basic transformations are used in most graphics
packages. But there are few additional transformations that are useful in certain
applications. Two such transformations are
A) Reflection Y
Reflected Original
B) Shear position Position
A) Reflection
A reflection is a transformation that produces a
mirror image of an object. The mirror image for a
two dimensional reflection is generated relative
to an axis of reflection by rotating the object 1800 X
about the reflection axis. Reflection axis can be a
Fig-5.6
line on xy-plane or perpendicular to the xy-plane.
Now consider these two cases: i) If reflection axis is Reflection of an object
a line on xy-plane- The rotation path of the object about the y-axis
about reflection axis is in a plane perpendicular to
the xy-plane.
ii) If reflection axis is a line perpendicular to the xy-plane-The rotation path is the xy-
plane.
Y
Y Y Y
Original
Position

X P
X
Reflected
position
X X

Fig-5.7 Fig-5.8 Fig-5.9 Fig-5.10


Reflection of an object about the x-axis(Fig-5.7), an axis perpendicular to the xy-
plane and passing through the coordinate origin(Fig-5.8), an axis which makes an
angle 450 with x-axis(Fig-5.9), an axis perpendicular to the xy-plane and passing
through point P(Fig-5.10) respectively.
B) Shear
Shear transformations have the property of preserving parallelism of lines, but not lengths
and angles. Through shear transformation the structure of the object gets distorted, but
parallel lines (if any) remains parallel. 2-D transformation shear transformations are of
two kinds:
a) shear along x-axis
b) shear along y-axis
a) Shear transformation along x-axis Transformation
An x-direction shear relative to the x-axis is produced with the transformation matrix.

1 shx ------------------------------------- 5.6


0 1

which transforms coordinate position as


x/=x + shx . y, y/=y

Fig-5.11 Fig-5.12
A unit square(fig-5.11) is converted to a parallelogram (fig-5.12) using the x direction
shear matrix with shx=1.
b) Shear transformation along y-axis Transformation
An y-direction shear relative to the y-axis is produced with the transformation matrix.

1 0
shy 1

which transformed coordinate position as


x/=x, y/=y+ shy . x

Fig-5.13
A unit square(fig-5.11) is converted to
a parallelogram (fig-5.13) using the y
direction share matrix with shy=1.

2D TRANSFORMATIONS –In General


In the above 4 types of transformation (except translation, which can be included in
general 2D transformation in homogeneous coordinates system) there are 4 distinct
matrices. Now consider general 2D transformation matrix as:

P/=T . P => x/ y/ = a b x y -------- 5.7


c d

Where (x, y) is the coordinate of initial point (original point) and (x/, y/) is the coordinate
of the transformed point (final position).
Transformation can be applied on an object by changing the value of a, b, c, d of matrix
T. The following table show different transformations on a point P for different value of
a, b, c, d:

a b c D CONDITION DESCRIPTION TRANSFOR-


MATION
b=c=0, a=d=1
No change in the coordinate of the
1 0 0 1 x/=x, y/=y
point P
b=c=0, d=1 No change along y-axis but stretch
u 1 x/=ax, y/=y
(u is any number) along the x-axis.
0 0
b=c=0, d=1 No change along x-axis but stretch
1 V x/=x, y/=dy
(v is any number) along the y-axis.
a=d=u>1, b=0, c=0 Pure enlargement in the scaling x/=ax, y/=dy
>1 0 0 >1
occur in both the directions.
a=d=u<1, b=0, c=0 Compression in the coordinate P
<1 <1
will be occur in both directions.
a≠d, b=0, c=0, Stretching will occur and will be
u V
a=u, d=v(u≠v) different in both the directions.
-1 1 a=-1, b=0, c=0, d=1 Reflection about y-axis x/=-x, y/=y
1 0 0 -1 a=1, b=0, c=0, d=-1 Reflection about x-axis x/=x, y/=-y
-1 -1 a=-1, b=0, c=0, d=-1 Reflection about origin x/=-x, y/=-y
Note: - Reflection, stretching and scaling involve only the diagonal term (a, d) of the
transformation matrix T
a=d=1, b=u, c=0 Shear transformation to x-
u 0 x/=x, y/=bx+y
coordinate
1 1
a=d=1, b=0, c=u Shear transformation to y-
0 u x/=x+cy, y/=y
coordinate
Note: - Off-diagonal term(b, c) produce shearing effect on the coordinate of P.

For origin the general 2D transformation equation will be

x/ y/ = a b 0 0
c d

=> x/=0, y/=0


Which implies that the transformation for origin does not depend on the transformation
matrix. So origin is invariant under general 2D transformation this is a limitation, which
we over come by the homogeneous coordinate system.
See demonstration 5.1.

HOMOGENEOUS COORDINATES SYSTEM AND MATRIX


REPRESENTATION
Translation, Rotation and Scaling are represented as
P/=T+P
P/=R.P
P/=S.P respectively.
Here other than translation all other transformations are represented by multiplication.
We would like to be able to represent all the transformations as product of two matrices
so that we can combine two or more transformations easily. Homogeneous coordinates
allow us to do so.
In Homogeneous coordinates we add a third coordinate to a point. So instead of being
representing a coordinate as (x, y) or (x/, y/), coordinates can be represented as (xh, yh, h)
or (xh/, yh/, h/) where xh=x/h, yh=y/h/, xh/=x//h/ if h and h/ are non-zero. If h or h/ is zero
then the points are known as points at infinity. The coordinates in homogeneous
coordinates system are called coordinate triples. So we can directly homogenize a point
just by adding 1 in the coordinate i.e. (x, y) can be represented as (x, y, 1)(dividing all the
coordinate triples by h).
In homogeneous coordinate system points (x, y, h) and (x/, y/, h/) will represent the same
point if and only if one is a multiple of other. Thus, (1, 2, 3) and (3, 6, 9) represent the
same points. But in this case, at least one of the homogeneous coordinates must be non-
zero. So (0, 0, 0) is not allowed.
In homogeneous coordinates, transformation matrices are also represented by 3X3 matrix
instead of 2X2 matrix.
Transformation matrices in homogeneous coordinate system are as follows:
Translation -

P/=P+T
P

where

P= x P/= x/
P

y x2 y/
1 1
and

T(tx , ty )= 1 0 tx -------------------------------- 5.8


0 1 ty
0 0 1

Rotation –
P/=R . P
P

R(θ)= cosθ -sinθ 0 --------------------------------- 5.9


sinθ cosθ 0
0 0 1

Scaling –
P/=S . P
P

S(sx , sy )= sx 0 0 -------------------------------- 5.10


0 sy 0
0 0 1

COMPOSITE TRANSFORMATION

Consider the following three problems fig 5.14 (a), (b), (c), (d)
1. Translate the point A (1,2) of triangle ABC to (3, 5)
2. Rotate it 900 counter clockwise about point A
3. Translate point A to origin O (0, 0)
We can easily solve these three problems individually. But if we want to apply these
three sequentially on the triangle, the combined transformation is called composite
transformation.
Here
for problem-1
tx=3-1[(x-coordinate of the final position) – (x-coordinate of the initial point)]=2
and
ty=5-2 [(y-coordinate of the final position) – (y-coordinate of the initial point)]=3
therefore, transformation matrix is

T(2, 3)= 1 0 2 (using equation 5.8)


0 1 3 -------------------------------------- (A)
0 0 1

C (4, 13)
y y
C (2,10)

A (3, 5) B (6, 5)

A (1, 2) B (4,2)
x x
O(0, 0) O(0, 0)

Fig – 5.14 (a) Fig – 5.14 (b)

Original position of the triangle ABC. Point A of Triangle ABC is


translated to point (3,5)

y y
B

C 900
B

A (3, 5)
C
x
O
x
O(0, 0) A (0, 0)

Fig – 5.14 (c) Fig – 5.14 (d)

Triangle ABC is rotated 90 0 about point A Triangle ABC is translate to origin


(0, 0)
For problem-2
θ=90 0
Therefore, transformation matrix for this rotation is

R(90 0)= cos90 0 -sin90 0 0 (using equation 5.9)


sin90 0 cos90 0 0
0 0 1

= 0 -1 0 (Putting the value of sinθ and cosθ)


1 0 0 ----------------------------- (B)
0 0 1

For problem-3

tx=0-3=-3
and
ty=0-5=-5

Therefore, transformation matrix is

T(-3, -5)= 1 0 -3 (using equation 5.8)


0 1 -5 ----------------------------- (C)
0 0 1

Now we have to derive the composite transformation matrix if the above mentioned three
transformations (problem1, 2, 3) are applied sequentially on the triangle. We can get this
composite transformation matrix by multiplying three transformation matrices of
equation (A), (B), (C).
Therefore the composite transformation matrix is
T(2, 3) . R(900) . T(-3, -5)

This is the general approach of getting composite matrix from individual transformations.

Das könnte Ihnen auch gefallen