# Types of Transformations (Reflection and Shearing) in Computer Graphics

**Computer Graphics | Reflection and Shearing**: In this tutorial, we are going to learn about the **Reflection and Shearing which are types of Transformation in computer graphics**, the ways in which an image is transformed in each of these methods.

Submitted by Monika Sharma, on May 06, 2020

## Reflection

The **reflection** is just like the mirror image of the original image. The mirror image can be either about the x-axis or the y-axis. In the reflection process, the size of the object does not change. We can also say that the reflection is a kind of rotation where the angle of rotation is 180 degrees, while the reflected object is always formed on the other side of the mirror and the size of the reflected image is the same as the size of the original image.

We can see reflection of object in these four ways:

- Reflection along X-axis
- Reflection along Y-axis
- Reflection along the line(x=y)
- Reflection perpendicular to XY-axis

Now let us understand reflection with the help of an example,

**Example:**

**Problem Statement:** Given a triangle with coordinate points * A (3, 4)*,

*,*

**B (6, 4)***. Apply the reflection on the X-axis and obtain the new coordinates of the object.*

**C (5, 6)****Solution:**

**Given -**

- Old corner coordinates of the triangle =
**A (3, 4), B (6, 4), C (5, 6)** - Reflection has to be taken on the X-axis

__For the co-ordinates A (3, 4)__

Let the new co-ordinates of corner A after reflection be = (X_{new}, Y_{new}).

When we apply the reflection equations, we get:

Xnew = X_{old} = 3

Y_{new} = -Y_{old} = -4

Thus, the new co-ordinates of corner A after reflection is = (3, -4).

__For the co-ordinates B (6, 4)__

Let the new co-ordinates of corner B after reflection be = (X_{new}, Y_{new}).

When we apply the reflection equations, we get-

X_{new} = X_{old} = 6

Y_{new} = -Y_{old} = -4

Thus, the new co-ordinates of corner B after reflection is = (6, -4).

__For the co-ordinates C (5, 6)__

Let the new coordinates of corner C after reflection be = (X_{new}, Y_{new}).

When we apply the reflection equations, we get-

X_{new} = X_{old} = 5

Y_{new} = -Y_{old} = -6

Thus, the new co-ordinates of corner C after reflection is = (5, -6).

Thus, the new co-ordinates of the triangle after reflection will be = A (3, -4), B (6, -4), C (5, -6).

## Shearing

**Shearing** is the transformation of an object which changes the shape of the object. The **shearing** can be in one direction or two directions. It is an ideal technique to change the shape of an existing figure. The sliding of layers of the object occurs while doing the same. Shearing can be done in three ways,

- Shearing in the X-direction
- Shearing in the Y-direction
- Shearing in the X-Y direction

Shearing in X axis can be done using this equation,

- X
_{new}= X_{old}+ Sh_{x}x Y_{old} - Y
_{new}= Y_{old}

Shearing in Y axis can be done using this equation,

- X
_{new}= X_{old} - Y
_{new}= Y_{old}+ Sh_{y}x X_{old}

Now let us understand shearing more clearly with the help of an example,

**Example:**

**Problem Statement:** Given a triangle with points * A (1, 1)*,

*and*

**B (0, 0)***. You need to apply shear parameter 2 on the X-axis and 2 on Y-axis and find out the new coordinates of the object.*

**C (1, 0)****Solution:**

**Given-**

- Old corner co-ordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
- Shearing parameter towards X-direction (Sh
_{x}) = 2, Y direction (Sh_{y}) = 2

**Shearing in X Axis**

__For the co-ordinates A (1, 1):__

Let the new co-ordinates of corner A after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}+ Sh_{x}x Y_{old}= 1 + 2 x 1 = 3 - Y
_{new}= Y_{old}= 1

Thus, the new co-ordinates of corner A after shearing is = (3, 1).

__For the co-ordinates B (0, 0):__

Let the new co-ordinates of corner B after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}+ Sh_{x}x Y_{old}= 0 + 2 x 0 = 0 - Y
_{new}= Y_{old}= 0

Thus, the new co-ordinates of corner B after shearing is = (0, 0).

__For the co-ordinates C (1, 0)__

Let the new co-ordinates of corner C after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}+ Sh_{x}x Y_{old}= 1 + 2 x 0 = 1 - Y
_{new}= Y_{old}= 0

Thus, the new co-ordinates of corner C after shearing is = (1, 0).

Thus, the new co-ordinates of the after shearing in X axis = A (3, 1), B (0, 0), C (1, 0).

**Shearing in Y Axis**

__For the co-ordinates A (1, 1)__

Let the new coordinates of corner A after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}= 1 - Y
_{new}= Y_{old}+ Sh_{y}x X_{old}= 1 + 2 x 1 = 3

Thus, the new co-ordinates of corner A after shearing is = (1, 3).

__For the co-ordinates B (0, 0)__

Let the new co-ordinates of corner B after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}= 0 - Y
_{new}= Y_{old}+ Sh_{y}x X_{old}= 0 + 2 x 0 = 0

Thus, the new co-ordinates of corner B after shearing is = (0, 0).

__For the co-ordinates C (1, 0)__

Let the new co-ordinates of corner C after shearing be = (X_{new}, Y_{new}).

When we apply the shearing equations, we get-

- X
_{new}= X_{old}= 1 - Y
_{new}= Y_{old}+ Sh_{y}x X_{old}= 0 + 2 x 1 = 2

Thus, new co-ordinates of corner C after shearing is = (1, 2).

Thus, the new co-ordinates of the triangle after shearing in Y axis is = A (1, 3), B (0, 0), C (1, 2).

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.