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

Computer Graphics

(Lecture 8)
2D Transformations
 Rotation changes the position and orientation of shapes by rotating
each of the points in the shape around a common point, or center of
rotation.
Rotation Proof
2D Transformations
 Translation simply moves an objects position by given offset.
 This is performed by adding the translation vector to the all co-
ordinates within the object.
Homogeneous Coordinates

Translation Scaling Rotation


Shearing
 Shearing a transformation that alters one of the coordinates
proportionally to the other coordinate(s) values and keep the other
coordinates with no change.

X values are changed proportional to y , while y values are the same


2D Shearing
 2D Shear along X-direction
 Shear in X direction is represented by the following set of
equations. x’ = x + sh y
x
y’ = y

where shx is the negative or positive fraction of Y coordinate of


P to be added to the X coordinate. Shx can be any real number
The matrix of form of shear in x-direction is given
by :
𝒙′ 𝟏 𝒔𝒉𝒙 𝟎 𝒙
𝒚′ = 𝟎 𝟏 𝟎 𝒚
𝟏 𝟎 𝟎 𝟏 𝟏
2D Shearing
 2D Shear along Y Direction
Similarly, shear along y-direction is given by
𝒙′ 𝟏 𝟎 𝟎 𝒙
x’ = x 𝒚′ = 𝒔𝒉𝒚 𝟏 𝟎 𝒚
y’ = shy x + y 𝟏 𝟎 𝟎 𝟏 𝟏

Combining the shear in X and Y directions,


𝒙′ 𝟏 𝒔𝒉𝒙 𝟎 𝒙
𝒚′ = 𝒔𝒉𝒚 𝟏 𝟎 𝒚
𝟏 𝟎 𝟎 𝟏 𝟏
Example for 2D Shearing

y y y y
Shx=2 Shy=2

x x x x
3D Transformation
 Elemental Transformations:
 Translation
 Rotation
 Scaling
 Shearing
 Three of them are affine and linear:
 Rotation, Scaling, and Shearing
 One is affine but non-linear
 Translation
Definitions of Transformations
 Projective ⊃ Affine ⊃ Linear
 Meaning that all linear transforms are also affine transforms, which are also
projective transforms.
 However, not all affine transforms are linear transforms, and not all
projective transforms are affine.
Definitions of Transformations
 Definitions:
 Linear Transform:
 Preserves parallel lines
 Acts on a line to yield either a line or a point
 The vector [0, 0] is always transformed to [0, 0]
 Examples: scale and rotate
 Affine Transform:
 Preserves parallel lines
 Acts on a line to yield either a line or a point
 The vector [0, 0] is NOT always transformed to [0, 0]
 Examples: translate
 Projective Transform:
 Does NOT preserve parallel lines
 Acts on a line to yield either a line or a point
 The vector [0, 0] is NOT always transformed to [0, 0]
 Examples: perspective camera
Definitions of Transformations
3D Translation
 Translation by (tx, ty, tz) is achieved using the following matrix:
1 0 0 tx 
0 1 0 ty 
M T (t x , t y , t z )   
0 0 1 tz 
 
0 0 0 1

 For example: translation by (1, 1, 1) is the following:


1 0 0 1
0 1 0 1
M T (1,1,1)   
0 0 1 1
 
0 0 0 1
3D Scaling

The scale formula changes the size of the object and


repositions the object with relative to the coordinate
origin.

Y -z

-x
(2,0,-4)
(4,0,-2)
-y
Z
Scaling with respect to a selected point

 Scaling with respect to a selected point (xf,yf,zf) can be represented


with the following transformation sequence:
 1: Translate the fixed point to the origin.
 2: Scale the object with respect to origin.
 3: Translate the fixed point back to its original position.

T(xf,yf,zf).S (sx,sy,sz) .T (-xf,-yf,-zf)

 e.g : scale the previous example around (2,0,-4)


Scaling with respect to a selected point

 Solution:
 1: Translate the object to system origin by T(-2,0,4)
 2: Scale the object by S (2,1,0.5)
 3:Translate the object back to (2,0,-4) by T (2,0,-4)
 p’ = T-1.S.T .p

transformation
Scaling with respect to a selected point

Y -z Y -z
Y -z

-x -x
-x

-y -y -y
Z Z Z

T(-2,0,4) S(2,1,0.5) T(2,0,-4)


𝑥′ 1 0 0 𝑥𝑓 𝑆𝑥 0 0 0 1 0 0 −𝑥𝑓 𝑥
𝑦′ 0 1 0 𝑦𝑓 0 𝑆𝑦 0 0 0 1 0 −𝑦𝑓 𝑦
 =
𝑧′ 0 0 1 𝑧𝑓 0 0 𝑆𝑧 0 0 0 1 −𝑧𝑓 𝑧
1 0 0 0 1 0 0 0 1 0 0 0 1 1
𝑥′ 1 0 0 2 2 0 0 0 1 0 0 −2 𝑥
𝑦′ 0 1 0 0 0 1 0 0 0 1 0 0 𝑦
 =
𝑧′ 0 0 1 −4 0 0 0.5 0 0 0 1 4 𝑧
1 0 0 0 1 0 0 0 1 0 0 0 1 1

𝑥′ 1 0 0 2 2 0 0 −4 𝑥
𝑦′ 0 1 0 0 0 1 0 0 𝑦
 =
𝑧′ 0 0 1 −4 0 0 0.5 2 𝑧
1 0 0 0 1 0 0 0 1 1

𝑥′ 2 0 0 −2 𝑥
𝑦′ 0 1 0 0 𝑦
 =
𝑧′ 0 0 0.5 −2 𝑧
1 0 0 0 1 1

You might also like