You are on page 1of 62

Geometrical

Transformations
Chapter 2
2D Geometrical Transformations
• Consider the red
triangle
- What transformation
would map the
triangle onto: triangle
A, triangle B, triangle
C, triangle D?
- What single
transformation would
map triangle A onto
triangle C?
TRANSFORMATIONS

• A change in the size, shape, orientation or position


of an object is called a transformation.
• Reflections, rotations, translations and
enlargements are transformations. We can describe
these transformations mathematically using
transformation geometry.
• In transformation geometry figures are changed
(or transformed) in size, shape, orientation or
position according to certain rules.
• The original figure is called the object and the new
figure is called the image
• Translations where every point moves a fixed distance
in a given direction
• Reflections or mirror images
• Rotations about a point through a given angle
• Enlargements and reductions about a point with a
given factor
• Stretches with a given invariant line and a given factor.
• Why are geometric transformations
necessary?
- For positioning geometric objects in 2D and 3D.
- For modeling geometric objects in 2D and 3D
- For viewing geometric objects in 2D and 3D
Assumption: Objects consist of points and lines.
• A point is represented by its Cartesian coordinates:
• P = (x, y)
Geometrical Transformation:
• Let (A, B) be a straight-line segment between the
points A and B.
• Let T be a general 2D transformation.
• T transforms (A, B) into another straight-line segment
(A’, B’), where:
• A’=TA and
• B’=TB
1. Translations
• A translation moves an object from one place to another.
Every point on the object moves the same distance in the same
direction
y
P

P x

x’= x + Δx
y’= y + Δy
• Translating a point (x, y) means to move it by (Δx, Δy).
• Matrix representation
2. Rotations
• When P(x, y) moves
under a rotation about O
through an angle of  to
a new position P’(x’, y’),
then OP = OP’ and POP’
=  where positive μ is
measured anticlockwise.
• O is the only point which
does not move under the
rotation.
• Matrix representation
Rotation in angle about a pivot (rotation) point
y (xr, yr)


yr
x
xr x  xr   x  xr  cos    y  yr  sin 

y
 x, y y  yr   x  xr  sin    y  yr  cos 

P  Pr  R   P  Pr 
  x, y 
cos   sin  
R
 xr , yr  x  sin  cos  
3. Translation and Rotation:
homogeneous coordinates
• Each of the above transformations with the exception
of translation can be represented as a row vector X,
Y and a 2 X 2 matrix. All the transformations above
can be represented as a product of a 1 X 3 row vector
and an appropriate 3 X 3 matrix.
• The conversion of a two-dimensional co-ordinate pair
(X, Y) into a 3-dimensional vector can be achieved
by representing the point as [X Y 1]. After
multiplying this vector by a 3 X 3 matrix, another
homogeneous row vector is obtained [X1 Y1 1].
• The first two terms in this vector are the co-ordinate
pair which is the transform of (X, Y). This three-
dimensional representation of a two- dimensional
plane is called homogeneous coordinates and the
transformation using the homogeneous co-ordinates
is called homogeneous transformation. The matrix
representations of the four basic transformations are
given below.
4. Scaling
Scaling an object consists of multiplying each of its
point component x and y by a scalar λx and λy,
respectively
x  x  s x , y   y  s y

Sx  x   s x 0   x
 y   0 
s y   y 
  
Sy
P  S  P
y Scaling about a fixed point  x f , y f 
x  x  sx  x f 1  sx 

x f , yf  y  y  s y  y f 1  s y 
x
P  P  S  P f  1 - S 
Non-uniform scaling
• Non-uniform scaling an object consists of multiplying
each of its point component x and y by a scalar λx
and λy, respectively, with λx ≠ λy.
5. Shearing
• Shearing an object consists of linearly deforming it
along either x-axis or y-axis or both.
6. Matrix 3x3 for 2D
affine transformations
General Rotation
Move to origin Rotate Move back

 xr , yr 

1 0 xr  cos   sin  0  1 0  xr 
0 1 yr    sin  cos  0   0 1  yr  

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

cos   sin  xr 1  cos    yr sin  


 
 sin  cos  yr 1  cos    xr sin  
 0 0 1 
General Scaling
Move to origin Scale Move back

x f , yf 

1 0 x f  Sx 0 0  1 0  x f   S x 0 x f 1  S x  
0 1  
 y f    0 Sy   
0   0 1  y f    0 Sy y f 1  S y 
0 0 1   0 0 1  0 0 1   0 0 1

 
Directional Scaling
x
S2
R 1    S  S1 , S 2   R   

 S1 cos 2   S 2 sin 2   S2  S1  cos  sin  0


 
y   S 2  S1  cos  sin  S1 sin 2   S 2 cos 2  0
  0 0 1 

S1
x x
S1  1

S2  2

  45O
y y
3D Geometrical
Transformations
Very similar to 2D. Using 4x4 matrices rather than 3x3.
Translation x  x  t x
y
y  y  t y

z  z  t z

 x, y, z   x   1 0 0 tx   x 
 x, y , z   y   0
  1 0 t y   y 

 z  0 0 1 tz   z 
z x      
 1  0 0 0 1  1 
1. General 3D Rotation

1. Translate the object such that rotation axis passes


through the origin.
2. Rotate the object such that rotation axis coincides
with one of Cartesian axes.
3. Perform specified rotation about the Cartesian axis.
4. Apply inverse rotation to return rotation axis to
original direction.
5. Apply inverse translation to return rotation axis to
original position.
y y y
P2
P2
P1
P1 P1
x x x
P2
z z z

y y y
P2 P2

P1 P1
P1
P2 x x x

z z z
1 0 0  x1 
0 1 0  y1 
The vector from P1 to P2 is: T
0 0 1  z1 
 
V  P2  P1   x2  x1 , y2  y1 , z2  z1  0 0 0 1 

Unit rotation vector: u  V | V |  a, b, c 

a   x2  x1  | V | y u   a, b, c 
b   y2  y1  | V |

c   z2  z1  | V |
x
a 2  b2  c 2  1
z
Rotating u to coincide with z axis

First rotate u around x axis to lay in x  z plane.


Equivqlent to rotation u 's projection on y  z plane around x axis.

cos   c b 2  c 2  c d , sin   b d .

 
We obtained a unit vector w  a, 0, b 2  c 2  d in x  z plane.
y u   a, b, c 
1 0 0 0
0 c d b d 0  u
R x    
0 b d c d 0 
   x
0 0 0 1
z
Rotate w counterclockwise around y axis.
w is a unit vector whose x  component is a, y  component is 0,

hence z  component is b 2  c 2  d . y u   a, b, c 
cos   d , sin    a

d 0 a 0  x
0 1 0 0 
R y    
 a 0 d 0 z
 
0 0 0 1 w   a, 0, d 

R    T1  R x 1    R y1     R z    R y     R x    T
cos   sin  0 0
 sin  cos  0 0 
R z    
 0 0 1 0
 
 0 0 0 1

R    T1  R x 1    R y1     R z    R y     R x    T

M R   

 a 2 1  cos    cos  ab 1  cos    c sin  ac 1  cos    b sin  


 
ba 1  cos    c sin  b 1  cos    cos  bc 1  cos    a sin  
2

 ca 1  cos    b sin  cb 1  cos    a sin  c 2 1  cos    cos  


 
Efficient 3D Rotations by Quaternions
Quaternions are extensions of complex numbers to 4-dimension.

q  s  ia  jb  kc   s , v  s : real v   a, b, c : imaginary

i 2  j 2  k 2  1, ij   ji  k , jk  kj  i, ki  ik  j

Addition: q1  q2   s1  s2 , v1  v 2 

Multiplication: q1q2   s1s2  v1  v 2 , s1 v 2 + s2 v1  v1  v 2 

1
2 
s,  v  , qq 1  q 1q  1, 0 
2 2 1
q  s  v  v, q 
q
Rotate a point position p   x, y, z  about the unit vector u.

y
 Quarternion representation:
u   
Rotation: q   cos , u sin 
 2 2
x Position: P   0, p  , p   x, y , z 
z
Rotation of P is carried out with the quarternion operation:

P  qPq 1   0, s 2p  v p  v   2 s  v  p   v   v  p 

This can be calculated by efficient HW for fast 3D rotations

when many rotation operations are involved.


2. 3D Scaling
y y
x  x  S x

y  y  S y

z  x  S z

z x z x
Enlarging object also moves it from origin

 x   S x 0 0 0  x 
 y   0 Sy 0 0   y 
P        SP
 z   0 0 Sz 0  z 
     
1  0 0 0 1  1 
Scaling with respect to a fixed point (not necessarily of object)
y y y

x f , yf , zf  x f , yf , zf  x f , yf , zf 
z x z x z x

y
Sx 0 0 1  S x  x f 
 
T  S  T1  
0 Sy 0 1  S y  y f 
xf , yf , z f  0 0 Sz 1  S z  z f 
 0 0 0 1 
z x
3. 3D affine transformations
Other 3D affine transformations
MATRIX NOTATION
(review)

You might also like