0% found this document useful (0 votes)
6 views

2D Trans

Uploaded by

Ali kombo hassan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

2D Trans

Uploaded by

Ali kombo hassan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Computer graphics - CE 473

2D TRANSFORMATIONS
Introduction
• What is transformations?
– The geometrical changes of an object from a
current state to modified state.
• Why the transformations is needed?
– To manipulate the initially created object and to
display the modified object without having to
redraw it.
2D Transformations
• 2 ways
– Object Transformation
• Alter the coordinates descriptions an object
• Translation, rotation, scaling etc.
• Coordinate system unchanged
– Coordinate transformation
• Produce a different coordinate system
Matrix Math
• Why do we use matrix?
– More convenient organization of data.
– More efficient processing
– Enable the combination of various
concatenations
• Matrix addition and subtraction
c a c
a
 = b d
b d
Basic Tranformations
• Translation
• Rotation
• Scaling
• Reflection
• Shear
Translation
• Translation is applied to an object by repositioning it along a straight-line path from one
coordinate location to another.

• New position (x’, y’) is obtained by adding the translation distance (t x,ty) (translation
vector or shift vector) to the original coordinate position (x,y).

x’ = x + tx
y’ = y + ty

• Matrix representation

• It is rigid- body transformation (moves objects without deformation)

• (line, Polygon, circle, ellipse)


Translation (contd..)
Scaling
• Scaling transformation alters the size of an object .
• Operation is carried out by multiplying the coordinate values (x, y) of each vectors
by scaling factor (sx,sy)  to produce transformed coordinates (x’, y’).

x’ = x . sx
y’ = y . sy

• Scaling factor sx scales object in x direction , while sy scales in y


direction.

Scaling
If the scale factors are in between 0 and 1  the
points will be moved closer to the origin  the
object will be smaller. P’

• Example :
• P(2, 5), Sx = 0.5, Sy = 0.5
• Find P’ ?
P(2, 5)

•If the scale factors are larger than 1  the points


will be moved away from the origin  the object P’
will be larger.

• Example :
• P(2, 5), Sx = 2, Sy = 2
• Find P’ ?
Scaling
• Uniform scaling , Differential scaling

• Based on fixed point

x’ = xf+ (x - xf) sx

y’ = yf + (y – yf) sy

x’ = x. sx + xf(1 – sx)

y’ = y. sy + yf(1 – sy)
Rotation
• Rotation is applied to an object by repositioning it along a
circular path in the xy plane.

• To generate a rotation of an object, we have to specify :


– Rotation angle (θ)
– Position of the rotation point/pivot point (xr,yr)

• Direction changes on rotation angle (based on


positive/negative)
2-D Rotation
(x’, y’)

(x, y)

x’ = x cos() - y sin()
 y’ = x sin() + y cos()
2-D Rotation

x = r cos (f)
y = r sin (f)
x’ = r cos (f + )
(x’, y’) y’ = r sin (f + )

Trig Identity…

(x, y) x’ = r cos(f) cos() – r sin(f) sin()


y’ = r sin(f) sin() + r cos(f) cos()

Substitute…


x’ = x cos() - y sin()
f y’ = x sin() + y cos()
2-D Rotation
• This is easy to capture in matrix form:

R=

• Rotation about the arbitrary pivot position (xr,yr)

x’ = xr + (x – xr) cos θ - (y - yr) sin θ y

Y’ = yr + (x - xr) sin θ + (y - yr) cos θ r


(x’,y’)

θ r
φ (x,y)
• Rigid-body transformation. yr
• (line, Polygons, circle, ellipse)
xr x
Matrix Representation
• Point in column-vector:
x
y
1

• Our point now has three coordinates. So our matrix is


needs to be 3x3.
• Translation
 x  1 0 t x   x 
 y  0 1 t    y 
   y  
 1   0 0 1   1 
Matrix Representation
• Rotation

 x  cos  sin  0  x 


 y  sin  cos 0   y 
  
 1   0 0 1  1 

• Scaling

 x  s x 0 0  x 
 y  0 sy 0   y 
  
 1   0 0 1  1 
Order of operations
So, it does matter. Let’s look at an example:
1. Translate 1. Rotate
2. Rotate 2. Translate
Other transformations
Reflection:
x-axis y-axis

 1 0 0   1 0 0
 0  1 0  0 1 0
   
 0 0 1  0 0 1
Other transformations
Reflection:
origin line x=y

  1 0 0  0 1 0
 0  1 0  1 0 0
   
 0 0 1
 0 0 1
Other transformations
Shear:
x-direction y-direction

 1 shx 0  1 0 0
0 1 0  sh
  y 1 0
 0 0 1  0 0 1
Shear
• Converted to a parallelogram
y (1,1) y
(0,1)
 1 sh x 0 (2,1) (3,1)
0 1 0
 (0,0) (1,0) x
(0,0) (1,0)
x
 0 0 1

x’ = x + shx · y, y’ = y
(Shx=2)

• Transformed to a shifted parallelogram


(Y = Yref)
y y
(1,1) (1,1) (2,1)
 1 sh x  sh x y ref  (0,1)
0 1  (1/2,0)
0 x
  (0,0) (1,0) (3/2,0)x
 0 0 1 
(0,-1)

(Shx=1/2, yref=-1)
x’ = x + shx · (y-yref), y’ = y

cgvr.korea.ac.kr
Shear
• Transformed to a shifted parallelogram
(X = Xref)

(0,3/2) (1,2)
 1 0 0  y y
 sh 1  sh y x ref  (1,1)
 y  (0,1)
 0  (0,1/2) (1,1)
0 1
x x
(0,0) (1,0) (-1,0)

x’ = x, y’ = shy · (x-xref) + y
(Shy=1/2, xref=-1)

cgvr.korea.ac.kr
Reflection
• Reflection with respect to the axis

 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 3 x
2’ 3’ 1

1’ 2
Reflection
 Reflection with respect to a Line

y
 0 1 0
 1 0 0
  x
 0 0 1

 Clockwise rotation of 45  Reflection about the x axis 


Counterclockwise rotation of 45 

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

Using Transformations (1)
• In 3D, many cubes make a city.
Using Transformations (2)
• The snowflake exhibits symmetries.
• We design a single motif and draw the whole
shape using appropriate reflections, rotations,
and translations of the motif.
use it 12 times
Using Transformations (3)
• A designer may want to view an object from
different vantage points.
• Positioning and reorienting a camera can be
carried out through the use of 3D affine
transformations.
Interactive Computer Graphics Chapter 9 - 29

You might also like