You are on page 1of 39

Computer

Graphics
2D and 3D Transformations
Functions
 f: x → y

 f: R → R

 f: R2 → R2

 f: (x, y) → 2
Domain, co-domain and
Range
 What can go into a function

is called the Domain
 What may possibly come

out of a function is called


the Co-domain
 What actually comes

out of a function is called


the Range
2D Transformation
What is transformation?
 Transformation: a function that sends each

point( or vertex) A, to another point T(A)


 The new object might have the same shape as

the old and new position or completely altered


What is transformation?
In general transformation means changing
some graphics on some some plane (such as 2D
or other) into something else by applying rules.
Transformation
Transformation enables to reposition of
graphics on the screen, change their size
and orientation.
Euclidean Transformation
 Rigid Body Transformations.

 Angles and distances are unchanged.

 Translation and Rotation are types of Euclidean

Transformation.
Homogeneous Coordinates
Any cartesian point P(X,Y) can be converted to
homogeneous coordinates by P'(Xh, Yh, h)

Via homogeneous coordinates representation of affine


transformations in a linear transformation is possible
due to the extra dummy coordinate we can add.
Homogeneous Coordinates

Homogeneous coordinates unify translation,
rotation, and scaling in one transformation
matrix.

Thus , a 2D transformation matrix is a 3x3
matrix.
Homogeneous Coordinates
Types of Transformations
 Translation

 Scaling

 Rotation

 Reflection

 Shearing/Skewing
Translation
 Translation moves an object to a different

position on the screen.


 Adding a translation coordinate (tx, ty) to the

original coordinate (X, Y) to get the new 2D


coordinate (X', Y').
2D Translation – In terms of homogeneous
coordinates representation

Inverse translation=>
Translation
Translation
The pair (tx, ty) is called the transition vector or
shift vector. It can be written as:
x' = x + tx , y' = y + ty
Matrix representation:

P' = P+T
Translation
For example, to translate a triangle with
vertices at original coordinates (2, 4), (6, 6),
(12, 4) by tx =3, ty =6, we compute as
followings: Translate vertex (2, 4):

Do the same for the other vertices.


Scaling
 Scaling refers to either expanding or compressing the
dimensions of the object.

 Mathematically represented as shown below:


X’ = X ∙ SX and Y’ = Y ∙ SY
2D Scaling – In terms of homogeneous
coordinates representation

Inverse scaling=>
Scaling
Scaling
Class work:

Scale a triangle with respect to the origin, with vertices at


original coordinates (10,20), (10,10), (20,10) by sx =2, sy =1.5
Reflection
 Via the scaling transformation, we can perform a switch of
sides of the coordinates along an axis, by negating the scaling
factor.
Reflection
 It cause a change in the ordering of the vertices.
 This can seriously impact many algorithms that depend on the
correct ordering of the vertices (such as Rasterization and
shading)
Rotation
 We rotate the object at particular angle theta from

its origin.
X = r cos Φ ........ (1)
Y = r sin Φ ......... (2)
Same way we can represent the point P'(X', Y') as:
X’ = r cos (Φ + θ) = r cos Φ cos θ – r sin Φ sin θ ...... (3)
Y’ = r sin (Φ + θ) = r cos Φ sin θ + r sin Φ cos θ ...... (4)

Substituting equation 1 and 2 in 3 and 4 respectively, we get

X’ = X cos θ – Y sin θ
Y’ = X sin θ + Y cos θ
Rotation
2D Rotation – In terms of homogeneous
coordinates representation

 The rotation matrix

 Rotation
Inverse rotation=>
Rotation
 Example: rotate a triangle about the origin

with vertices at original coordinates (2, 4), (6,


6), (12, 4) by 60 degrees.
Shearing

There are two shear transformations X-Shear and Y-
Shear. One shifts X coordinates values and other shifts
Y coordinate values.

However, in both the cases, only one coordinate
changes its coordinates and other preserves its values.

Shearing is also termed as Skewing.
Shearing
Shearing
Example: Start with a triangle having
vertices (0, 0), (3, 0), and (3, 2). Rotate this
triangle by π∕6 radians counterclockwise
around the origin.
Example
 Reflect through the y-axis

 Stretch in y direction (2x)


3D Transformation
3D Transformation
Similar to their usage in 2D, homogeneous coordinates
in 3D are used for enabling representation of
transformations in matrix multiplication format.
(x, y, z, w) =>(x/w, y/w, z/w).
Right Hand System

Look toward origin from a positive axis.


A counter-clockwise rotation transforms one axis to
another.
x: y → z, y: z → x, z: x → y.

Some graphic systems use the left hand system.
3D Translation
3D Scaling
3D Rotation – w.r.t to z-axis
3D Rotation – w.r.t to y-axis
3D Rotation – w.r.t to x-axis

You might also like