Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 56

Transformation

2D and 3D
Dept. of Computer Science and Engineering
Islamic University, Kushtia
Dimensions

y
y

x
x

z
Transformations

 Many applications need altering or manipulating displays


Transformations
There are two types of Transformation

Geometric Transformation Coordinate


Transformation
Object Transformed Coordinate Transformed
2D Transformation

 Given a 2D object, transformation is to change the


object’s
 Position (translation)
 Orientation (rotation)
 Size (scaling)
 Shapes (shear)
2D Transformations
How many way the object can be transformed?

Three Basic Types of Transformation


• Translation y
y
• Rotation
• Scaling x
x

y
Another Transformations are
• Reflection
x
• Shear
Translation
 Re-position a point along a straight line
 Given a point (x, y), and the translation distance (tx, ty)

The new point: (x’, y’)


x’ = x + tx
(x’,y’)
y’ = y + ty
or P’ = P + T ty

 x  x t x  (x,y)
tx
P   , P    , T   
 y  y  t y 
 x  x  t x 
 y    y  t 
   y
Translation

 How to translate an object with multiple


vertices?

Translate individual
vertices
2D Rotation
 Default rotation center: Origin (0,0)

Rotate counter clockwise


(Positive Rotation)

The rotation point/ Pivot point –


The point at which the object is to be rotate

 Rotate clockwise
(Negative Rotation)
Rotation

(x,y) -> Rotate about the origin by  (x’,y’)

(x’, y’)  (x,y)


r
How to compute (x’, y’) ? 

x = r cos () y = r sin ()

x’ = r cos () y = r sin ()


Rotation

x = r cos () y = r sin ()


x’ = r cos () y = r sin () (x’,y’)

x’ = r cos () (x,y)



= r cos() cos() – r sin() sin() r
= x cos()– y sin() 

y’ = r sin ()
= r sin() cos() + r cos()sin()
= y cos() + x sin()
Rotation
(x’,y’)
x’ = x cos() – y sin()
(x,y)
y’ = y cos() + x sin() 
r

Matrix form?

x’ =
cos() -sin() x
y’ sin() cos() y
P/ = R(). P
Rotation
 How to rotate an object with multiple
vertices?


Rotate individual
Vertices
Scaling
Scale: Alter the size of an object by a scaling factor
(Sx, Sy), i.e.

x’ = x . Sx  x '  s x 0  x
P/ = S. P
 y '   0 s y   y 
y’ = y . Sy   

Fixed point – The point that used to control the location of a scaled object

(4,4)

(2,2) Sx = 2, Sy = 2

(2,2)
(1,1)
2D Scaling

(4,4)

(2,2) Sx = 2, Sy = 2

(2,2)
(1,1)

 Not only the object size is changed, it also moved!!


 Usually this is an undesirable effect
 We will discuss later (soon) how to fix it
Put it all together

 x   x  t x 
Translation:     y  t  P=T + P
 y   y

 x' cos   sin    x 


Rotation:  y '   sin  cos    y 
P=R  P
  

 x'  s x 0  x
Scaling:  y '   0 s y   y 
P=S  P
  
Matrix Representation and
Homogeneous Coordinates
 Many graphics applications involve sequences of geometric
transformations. Example
 In animation, an object to be translated and rotated at each
increment of the motion.
 In design and picture construction applications, translations,
rotations, and scalings are used to fit the picture components
into their proper positions.
 Rotation and Scaling matrix are 2 by 2 and point P is multiplied with
matrix R or S
 Translation matrix is 2 by 1 and it is add with point P
 The multiplicative and translational terms for two-dimensional
geometric transformations into a single Matrix representation by
expanding the 2 by 2 matrix representations to 3 by 3 matrices.
 This allows us to express all transformation equations as matrix
multiplications
Homogeneous Coordinates
Any 2D transformation can be described uniquely by a 3x3 matrix, if
the Cartesian coordinates (x, y) is represented by the homogeneous
coordinate triple (xh, yh, h),
where xh yh
x , y
h h
h can be any real value ≠ 0,
for simplicity h=1 is used here

•The term homogeneous coordinates is used in mathematics to refer to the effect of


this representation on Cartesian equations.
•When a Cartesian point (x, y) is converted to a homogeneous representation (xh, yh,
h), equations containing x and y, such as f(x, y) = 0, become homogeneous equations
in the three parameters xh, yh, and h.
•This just means that if each of the three parameters is replaced by any value v times
that parameter, the value v can be factored out of the equations.
Homogeneous Matrix Representation

Homogeneous coordinate representation of 2D Translation

 x  1 0 tx   x 
 y    0 1 ty   y
    

1    0 0 1 1 
This translation operation can be written in the abbreviated form

P '  T (t x , t y )  P
T(tx, ty) is the 3 by 3 translation matrix
Homogeneous Matrix Representation

 Homogeneous coordinate representation of 2D Rotation


 x  cos   sin  0  x 
 y   sin  cos  0  y
    

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

 This translation operation can be written in the


abbreviated form
'
P  R( )  P
Homogeneous Matrix Representation

 Homogeneous coordinate representation of 2D


Scaling   
x  sx 0 0 x 
 y    0 s 0
 
   y  y
1  0 0 1  1 
 
 This scaling operation can be written in the
abbreviated form
'
P  S ( sx, sy )  P
Composite transformation matrix
 We can set up a matrix for any sequence of
transformations as a composite transformation matrix
by calculating the matrix product of the individual
transformations.
 Forming products of transformation matrices is often
referred to as a concatenation, or composition of
matrices.
Composite transformation matrix
 Translations
If two successive translation vectors T(tx1, ty1) and T(tx1, ty1) are
applied to a coordinate position P (x, y) , the final transformed
location P/(x/, y/) is calculated as

P   T (t x 2 , t y 2 ).{T (t x1 , t y1 ).P}
P   {T (t x 2 , t y 2 ).T (t x1 , t y1 )}.P

1 0 t x 2  1 0 t x1  1 0 t x1  t x 2 
0 1 t .0 1 t   0 1 t  t 
 y2   y1   y1 y2 
0 0 1  0 0 1  0 0 1 
Composite transformation matrix
 Rotation
Two successive rotations applied to point P(x, y) produce
the transformed position

P   R ( 2 ).{R (1 ).P}


 {R ( 2 ).R (1 )}.P
But R ( 2 ).R (1 )  R ( 2  1 )
Finally P   R ( 2  1 ).P
Composite transformation matrix
 Scaling
 Concatenating transformation matrices for two
successive scaling operations produces the following
composite scaling matrix
s x2 0 0  s x1 0 0  s x1.s x 2 0 0
 0 s y2 0. 0 s y1 0   0 s y1.s y 2 0

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

S ( s x 2 , s y 2 ).S ( s x1 , s y1 )  S ( s x1.s x 2 , s y1 , s y 2 )
General Two-Dimensional Pivot-Point
Rotation
 we can generate a 2D rotation about any other pivot
point (xr, yr) by performing the following sequence of
translate-rotate-translate operations
1. Translate the object so that the pivot-point position is
moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned
to its original position.
General Two-Dimensional Pivot-Point
Rotation

(xr,yr) (xr,yr) (xr,yr) (xr,yr)

The composite transformation matrix for this sequence


is obtained with the concatenation:
1 0 xr  cos   sin  0  1 0  xr  cos   sin  xr (1  cos  )  yr sin  
0 1 y  sin  cos  0  0 1  y   sin  cos  y (1  cos  )  x sin  
 r  r  r r 
0 0 1  0 0 1  0 0 1  0 0 1 

•Which can be expressed in the form


T ( xr , yr )  R( )  T (  xr ,  yr )  R ( xr , yr ,  )
General Fixed-Point Scaling

Similarly, we can obtain the matrix representation of


General 2D Fixed-Point Scaling.

(xr,yr) (xr,yr) (xr,yr) (xr,yr)

Translate Scale Translate


General Fixed-Point Scaling
1. Translate the object to so that the fixed point coincides
with the coordinate origin.
2. Scale the object with respect to the coordinate origin.
3. Use the inverse of the translation in step (1) to return
the object to its original position.

T x f , y f  S s x , s y  T  x f , y f   S x f , y f , s x , s y 

1 0 xf  s x 0 0 1 0  xf  s x 0 x f (1  s x ) 
0 1 yf 0 sy 0  0 1  yf 0 sy y f (1  s y )
    
0 0 1   0 0 1 0 0 1   0 0 1 
General 2D Scaling Directions

 We can scale an object in other directions by rotating the


object to align the desired scaling directions with the
coordinate axes before applying the scaling transformation.
 Suppose we want to apply scaling factors with values
specified by parameters s1 and s2 in the directions shown in
the following fig.
y s2

x

s1
General 2D Scaling Directions
To accomplish the scaling without changing the orientation of the object.
1. We first perform a rotation so that the directions for s1 and s2
coincide with the x and y axes, respectively.
2. Then the scaling transformation S(s1,s2) is applied.
3. An opposite rotation to return points to their original orientations.

 cos  sin  0  s1 0 0 cos   sin  0


 sin  cos  0   0 s2 0   sin  cos  0

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

 s1 cos 2   s2 sin 2  ( s2  s1 ) cos  sin  0


 
R 1 ( )  S ( s1 , s2 )  R( )   ( s2  s1 ) cos  sin  s1 sin 2   s2 cos 2  0
 0 0 1

General 2D Scaling Directions
For example, we turn a unit square into a parallelogram by
stretching it along the diagonal from (0,0) to (1,1).
 s1 cos 2   s 2 sin 2  ( s 2  s1 ) cos sin  0
  2 3 / 2 1 / 2  1
 ( s 2  s1 ) cos  sin  s1 sin 2   s2 cos 2  0 2  1 / 2 3 / 2.1
 0 0 1     

1 cos 2 450  2 sin 2 450 (2  1) cos 45 0 sin 450 0 3 / 2 1 / 2 0 1 / 2  3 / 2 1 / 2 0 0
    3 / 2  1 / 2 3 / 2 0.1
 ( 2  1) cos  sin  1sin 2 45 0  2 cos 2 450 0  1 / 2 3 / 2 0     
 0 0 1  0 0 1  1   0 0 1 1
 

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

Scale
Reflection
 A reflection is a transformation that produces a mirror
image of an object.
x-axis y-axis origin
1 0 0    1 0 0   1 0 0
0  1 0   0 1 0  0  1 0
     
0 0 1  0 0 1  0 0 1

y 1 y y
1 1’ 1’

2 3 2 3 3’ 2 3’ 2
x x x
2’ 3’ 3
1

1’ 2
Reflection

y 0 1 0 
1 0 0 
Reflection about the diagonal  
y=x 0 0 1
x

 Reflections about any line y = mx+c in the xy plane can be


accomplished with a combination of translate-rotate-reflect
transformations.
1. First translate the Line so that it passes through the origin.
2. Rotate the line onto one of the coordinate axes (x or y)
3. Reflect about that axis.
4. Restore the line to its original position with the inverse rotation and
translation transformations.
Shear
 A transformation that distorts the shape of an object such
that the transformed shape appears as if the object were
composed of internal layers that had been caused to slide
over each other is called a shear.
 Two common shearing transformations are those that shift
coordinate x values and those that shift y values.

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


the transformation matrix
 The value of shx may any real number
x = x + shx · y, y = y y y
(1,1) (2,1) (3,1)
(0,1)
1 sh x 0
0 1 0
(0,0) (1,0) x
(0,0) (1,0)
x

0 0 1
Shear
 We can generate x-direction shears relative to other
reference lines with yref= - 1
 Now, coordinate positions are transformed as
x = x + shx · (y - yref), y = y
1 sh x  sh x  y ref 
0 1 0 
 
0 0 1 

The following Fig. illustrates the


conversion of a square into a
parallelogram with shy=0.5 and
yref= ­1
Shear
 Similarly an y-direction shear relative to the y axis is produced with
the transformation matrix
 1 0 0
 sh 1 0
x = x, y = shy · x + y  y 
 0 0 1

 Similarly we can generate y-direction shears relative to the lines xref=


-1
 Now, coordinate positions are transformed as
x = x + shy · (y - yref), y = y  1 0 0 
 sh 1  sh .x 
 y y ref 
 0 0 1 

Shearing operations can be expressed as a


sequences of basic transformations. Such
as a series of rotation and scaling matrices
Coordinate Transformation
 Coordinate transformation is simply reverse to geometric
transformation. Following figures illustrate this

4 3

2 Transformed

4 Original
Coordinate Transformation

Rotation

 x'  cos  sin    x 


 y '   sin  cos    y 
  
Coordinate Transformation
1 
Shear 0
 x'  s x  x
 y '    
1  y
  0
 s y 

2
4

Transformed
Original

4 2
Affine Transformation
 Translation, Scaling, Rotation, Shearing are all affine
transformation
 Affine transformation – transformed point P’ (x’,y’) is
a linear combination of the original point P (x,y), i.e.
x’ axx axy bx x
y’ = ayx ayy by y
1 0 0 1 1

• Affine transformations have the general properties


that parallel lines are transformed into parallel lines
and finite points map to finite points.
Affine Transformation
 Another affine transformation is the conversion of coordinate
descriptions from one reference system to another, which can
be described as a combination of translation and rotation

 An affine transformation involving only rotation, translation, and


reflection preserves angles and lengths, as well as parallel lines.

 For these three transformations, the lengths and angle between


two lines remains the same after the transformation.
Composing Transformation

 Composing Transformation – the process of applying


several transformation in succession to form one
overall transformation
 If we apply transform a point P using M1 matrix first,
and then transform using M2, and then M3, then we
have:
(M3 x (M2 x (M1 x P ))) = M3 x M2 x M1 x P
(pre-multiply)
M
Three-Dimensional Transformations
3D matrices

 Methods for geometric transformations in three


dimensions are extended from two-dimensional methods
by including considerations for the z coordinate.

 A three-dimensional position, expressed in


homogeneous coordinates, is represented as a four-
element column vector. Thus , each geometric
transformation operator is now 4 by 4 matrix.
3D Translation
TP = (x + tx, y + ty, z + tz)
Y

1 0 0 tx   x
0 (x, y , z )
0 t y 
 y
 1  
0 0 1 tz  z
    T(tx, ty, tz)
0 0 0 1 1 
(x, y, z)
X
Inverse Translation

1 0 0  tx   x
0   y
 1 0 ty    Z
0 0 1  tz   z 
   
0 0 0 1  1
 
3D Scaling
sx 0 0 0  x 
0 sy 0 0  y 
 SP = (sxx, syy, szz) 
0 0 sz 0  z 
  
0 0 0 1  1 

Inversion
General scaling
 Scaling with respect to a selected fixed position (xf, yf, zf)
can be represented with the following transformation
sequence:

1. Translate the fixed point to the origin.


2. Scale the object relative to the coordinate origin
3. Translate the fixed point back to its original position.
3D Rotation
3D Rotation
3D Rotation
General Rotation
 Rotating about an axis that is parallel to one of the coordinates
axes.
 Step1, Translate the object so that the rotation axis coincides
with the parallel coordinate axis.
 Step2, Perform the specified rotation about that axis.
 Step3, Translate the object so that rotation axis is moved back
to its original.

 A coordinate position P is transformed with the sequence

P '  T 1  Rx ( )  T  P
General Rotation
 When an object is to be rotated about an axis that is not
parallel to one of the coordinate axes, we need to
perform some additional transformations.

1. Translate the object so that the rotation axis passes


through the coordinate origin
2. Rotate the object so that the axis of rotation coincides
with one of the coordinate axes.
3. Perform the specified rotation about that coordinate
axis.
4. Apply inverse rotations to bring the rotation axis back to
its original orientation.
5. Apply the inverse translation to bring the rotation axis
back to its original position.

3D Shear
 Shearing transformations can he 1 0 shx 0  x 
0 0  y 
used to modify object shapes
 1 shy
 the following transformation produces a z
-axis shear 0 0 1 0  z 
  
z z 0 0 0 1  1 

y
y
x x

You might also like