Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

2D Transformations - Reflection and Shearing

2D Composite Transformations
Overview
Homogeneous Coordinates
Reflection
Shearing
Graphics applications involves sequences of geometric transformations.
Efficient approach is needed to combine the transformations so that the
final coordinates are obtained directly.
Combine the multiplicative and the translational terms for 2d geometric
transformations into single matrix multiplication by homogenous
coordinates.
Homogeneous coordinates seem unintuitive, but they make graphics
operations much easier
Represent each 2D coordinate position (x, y) with the homogenous
coordinate triple (xh, yh, h).
Represent each 2D coordinate position (x, y) with the homogenous
coordinate triple (xh, yh, h). Where
 xh   h  x 
xh yh
x= y= P =  yh  = h  y 
h h
 h   h 

General homogeneous representation can also written as (h.x,h.y,h) set h=1.


Transformations of translation, scaling and rotation can be represented
using Homogeneous coordinates.
Homogeneous Transformation Coordinates
1 0 t x 
Translation T t x ,t y = 0 1 t y 
0 0 1 
P' = T t x ,t y  P

Rotation cosθ  sinθ 0


Rθ  =  sinθ cosθ 0
 0 0 1
P' = Rθ   P

 s x 0 0
Scaling S s x , s y =  0 s y 0
 0 0 1
P = S s x , s y  P
Composite Transformations
Application of a sequence of transformations to a point:
P  M 2  M 1  P
 MP

Composite transformations is formed by calculating the matrix


product of the individual transformations and forming products of
transformation matrix.
Composite Transformations-
Translation
First: composition of similar type transformations
If we apply to successive translations to a point:

P  T(t 2 x , t 2 y ) {T(t1x , t1 y )  P}
 {T(t 2 x , t 2 y )  T(t1x , t1 y )}  P
P AND P’ are represented as homogenous coordinate values.
1 0 t 2 x  1 0 t1x  1 0 t1x  t 2 x 
T t 2 x ,t 2 y  T t1x ,t1 y = 0 1 t 2 y   0 1 t1 y  = 0 1 t1 y  t 2 y  = T t1x + t 2 x ,t1 y + t 2 y 
0 0 1  0 0 1  0 0 1 

Successive translations are additive


Composite Transformations-Rotation

Two successive rotations applied to the point p produce the


transformed position
P’=R(θ) {R (Ф).P}={R(θ) .R (Ф)}.P
cosθ  sinθ 0 cos  sin 0
R θ   R φ =  sinθ cosθ 0   sin cos 0 =
 0 0 1  0 0 1
cosθcosφ  sinθsinφ  cosθsinφ  sinθcosφ 0 cos(θ + φ)  sin(θ + φ) 0
sinθcosφ + cosθsinφ  sinθsinφ + cosθcosφ 0 =  sin(θ + φ) cos(θ + φ) 0 = R θ + φ

 0 0 1  0 0 1

Two successive rotations are additive.


Composite Transformations-
Scaling
Two successive scaling operations produces the following
composite scaling matrix

s2x 0 0 s1x 0 0 s1x  s2x 0 0


Ss2x ,s2y  Ss1x ,s1y =  0 s2y 0   0 s1y 0 =  0 s1y  s2y 0 = Ss1x  s2x ,s1y  s2y 
 0 0 1  0 0 1  0 0 1

•The resulting matrix indicates the successive operations are


multiplicative.
Composite Transformations
Combining transformations reduces to matrix multiplication, e.g.
◦ R(r,) = T(r)* R(θ)* T(-r)
In general: multiplication of a 3x3 with another 3x3 matrix
requires 3*3*3 = 27 multiplications and 2*3*3 additions.
In 2D transformations, the third row of the matrices is always [0
0 1] and should never be calculated.
In addition, in homogeneous coordinates the third component of
the vectors is always one: (x,y,1).
Composite converts all to matrix multiplications thus improving
computational efficiency
Rotation around a pivot point
Rotations about any selected pivot point (xr,yr) by
performing the following sequence: T xr , y r 
◦ Translate the object so that the pivot point
moves to the origin
◦ Rotate around origin
◦ Translate the object so that the pivot point is
back to its original position
Txr , yr   R θ   T xr , yr  =
R  
1 0 xr  cosθ  sinθ 0 1 0  xr 
0 1 y    sinθ cosθ 0  0 1  y  =
 r    r

0 0 1   0 0 1  0 0 1 
T xr , y r 
cosθ  sinθ xr 1  cosθ + yr sinθ 
 sinθ cosθ y 1  cosθ   x sinθ 
 r r 
 0 0 1 
Scaling with respect to a Fixed Point

◦ Translate object to origin so fixed point coincides with origin


◦ Scale the object with respect to origin T x f , y f 
◦ Translate back by inverse translation.

Tx f , y f  Ssx , sy  T x f , y f =


1 0 x f  sx 0 0 1 0  x f 
S s x , s y 
0 1 y    0 s 0  0 1  y  =
 f  y   f

0 0 1   0 0 1 0 0 1 


sx 0 x f 1 sx 
 0 s y 1 s  Tx f , y f 
 y f y 

 0 0 1 
Concatenation Properties
Matrix multiplication is associative, evaluate matrix products using
left-to-right or right-to-left associative grouping.
Matrix composition is not commutative. So careful when applying
a sequence of transformations.
Reversing the order in which the sequence of transformations is
performed may affect the transformed position of an object.
pivot same pivot
REFLECTION

A transformation that produces a mirror image of an object

Image is generated relative to an axis of reflection by rotating the object


180° about the reflection axis
◦ Reflection axis is xy plane – rotation path about the axis is in the plane
perpendicular to xy plane
◦ Reflection axis perpendicular to xy plane – rotation path is in the xy
plane

14
2D REFLECTION
x-axis y-axis
Reflection about the line Reflection about the line
y=0 x=0

1 0 0  1 0 0
0  1 0  0 1 0
   
0 0 1  0 0 1
Transformation keeps x values but
Transformation keeps y values but flips
flips the y values
the x values
15
2D REFLECTION
Reflection relative to Reflection axis as the
the coordinate origin diagonal line x=y

0 1 0
1 0 0 

 0 0 1 
  1 0 0
 0  1 0
 
 0 0 1
Transformation flips both x values
and y values by Reflecting relative
to the coordinate origin 16
2D REFLECTION

Elements of the reflection matrix can be set to values other than ±1.

Reflection parameter:
◦ >1 – shifts the mirror image of a point farther from the reflection axis.
◦ <1 – brings the mirror image of a point closer to the reflection axis.

Thus, a reflected object can also be enlarged, reduced or distorted.

17
2D SHEAR
Transformation that distort the shape of an
object.

Slide to another shape

Internal layers are shifted w.r.t. each other

2 common shearing transformation


◦ Shift coordinate x values
◦ Shift coordinate y values

18
2D SHEAR

An x-direction shear relative to the x axis is produced with the


transformation matrix
1 shx 0
0 1 0
0 0 1

which transforms coordinate positions as


x’ = x + shx . y, y’ = y

19
2D SHEAR
Any real number can be assigned to the shear parameter shx.

A coordinate position (x, y) is then shifted horizontally by an


amount proportional to its perpendicular distance ( y value)
from the x axis.

y y

shx = 2

(0, 1) (1, 1) (2, 1) (3, 1)

x x
(0, 0) (1, 0) (0, 0) (1, 0)

20
2D SHEAR

We can generate x-direction shears relative to other reference


lines with
1 sh x  sh x  y ref
0 1 0
0 0 1

Now, coordinate positions are transformed as

x’ = x + shx( y – yref) , y’ = y

21
EXAMPLE

shx=0.5 and yref = -1

y y

(0, 1) (1, 1) (1, 1) (2, 1)

x x
(0, 0) (1, 0) (1/2, 0) (3/2, 0)

yref = -1 yref = -1

22
2D SHEAR

A y-direction shears relative to other reference lines can


generate with
1 0 0
sh y 1  sh y  x ref
0 0 1

Now, coordinate positions are transformed as

x’ = x, y’ = y + shy( x – xref)

23
EXAMPLE

shy=0.5 and xref = -1

y y
(1, 2)

(0, 3/2)
(0, 1) (1, 1)
(1, 1)
(0, 1/2)
x x
(0, 0) (1, 0) xref = -1
xref = -1

24
Transformations Between the
Coordinate Systems
Between different systems: Polar coordinates to cartesian
coordinates
Between two cartesian coordinate systems. For example,
relative coordinates or window to viewport transformation.
Transformations Between the
Coordinate Systems
How to transform from x,y
to x',y' ?
y
Superimpose x',y' to x,y
Transformation:
◦ Translate so that (x0,y0) y0
moves to (0,0) of x,y
◦ Rotate x' axis onto x axis x0 x
y

R θ   T  x0,  y0 

x
Transformations Between the
Coordinate Systems
Alternate method for rotation: y
Specify a vector V for positive
y' axis:

unit vector in the y' direction :


V
= v x ,v y 
V
v= x
V

unit vector in the x' direction, rotate v clockwise 90


u = v y ,v x = u x ,u y 
Transformations Between the
Coordinate Systems
Elements of any rotation matrix can be expressed as elements of a
set of orthogonal unit vectors:

u x uy 0  v y  vx 0
R =  v x vy 0 = v x vy 0
 0 0 1  0 0 1 y
Choose the directions for v relative to P
position P0 .
The components of v calculated as P0

P  P0 x
v=
P  P0  U is obtained as perpendicular to v
Affine Transformations
•An affine transformation is an important class of linear 2-D geometric
transformations which maps variables (e.g. pixel intensity values
located at position (x,y) in an input image) into new variables (e.g.
in an output image (x’,y’) by applying a linear combination of
translation, rotation, scaling and/or shearing (i.e. non-uniform
scaling in some directions) operations.
•Coordinate transformations of the form:

x' = a xx x + a xy y + bx
y' = a yx x + a yy y + by
Translation, rotation, scaling, reflection, shear. Any affine
transformation can be expressed as the combination of these.
Summary
Homogeneous coordinates
Reflection and shearing – w.r.t origin and fixed point
Transformation between systems
Affine transformations

You might also like