# Types of Transformations in Computer Graphics

**Computer Graphics | Types of Transformations**: In this tutorial, we will be explaining **Translation, Rotation, Scaling, Reflection and Shearing**, etc.

Submitted by Monika Sharma, on April 30, 2020

## What is Transformation?

**Transformation** refers to the mathematical operations or rules that are applied on a graphical image consisting of the number of lines, circles, and ellipses to change its size, shape, or orientation. It can also reposition the image on the screen.

Transformations play a very crucial role in computer graphics.

## Types of Transformations

There are various types of transformations in computer graphics through which an image can be processed, edited ad altered. Some basic and most commonly used types of these transformations are:

- Translation
- Rotation
- Scaling
- Reflection
- Shearing

### Translation

Translation refers to a technique in which a point is shift from one place to another, whose distance is known.

Consider a point A(x_{1}, y_{1}) be shifted to another point B (x_{2}, y_{2}). Now we only know the shifting distance t_{x} along x-axis and t_{y }along y-axis.

Now, the new coordinates (x_{2}, y_{2}) can be calculated as:

x_{2} = x_{1 }+ t_{x}

y_{2 }= y_{1 }+ t_{y}

**For example:**

Suppose we want to shift a point with coordinates at A(30,100) and distance along x-axis is 10 units and 20 units along y-axis.

Using translation:

Here t_{x }= 10 ;

and t_{y }= 20

New coordinates A^{’ }(x_{2}, y_{2}):

x_{2 }= 30 + 10 = 130

y_{2 }= 100 + 20 = 120

The point will be shifted to A^{’ }(130, 120 ).

### Rotation

Rotation refers to mathematical operation in which the graphical object is rotated about an angle (θ) to the axis.

Rotation is of two types: anti-clockwise and clockwise rotation.

Suppose we want to rotate a point with coordinates A (x_{1}, y_{1}) clockwise through an angle θ about the origin

Then the new coordinates A^{’ }(x_{2}, y_{2}):

x_{2 }= x_{1 }cosθ + y_{1 }sinθ

y_{2 }= x_{1 }sinθ - y_{1 }cosθ

### Scaling

Scaling refers to a mathematical rule applied to change the size of the image.

If the value of scaling factors is negative, the size is decreased and when the value is positive, the size of the image is increased.

Suppose the point with coordinates A (x_{1, }y_{1}) is to be scaled by a factor s_{x} along the x-axis and s_{y }along the y-axis.

Hence the new coordinates after scaling will be:

x_{2} = x_{1} x s_{x}

y_{2} = y_{1} x s_{y}

Translation, rotation and scaling are termed as basic translations.

### Other Transformations

The other two transformation techniques are as follows,

### Reflection

Reflection refers to the mirror image of the original graphical object. It is an 180^{o} rotation operation.

Reflection can be done about following ways:

- x-axis
- y-axis
- the origin and
- A plane perpendicular to the origin

### Shearing

Shearing is a transformation in which the shape of the object is slanted about the axis.

**In y-shearing:**

The new-coordinates will be:

x'^{ }= x

y'^{ }= y + s_{y }x

**In x-shearing:**

The new-coordinates will be:

x' = x + s_{x }y

y' = y

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.