# Translations in Computer Graphics

**Computer Graphics | Translations**: In this tutorial, we are going to learn about Translation which is a type of Transformation in computer graphics, type of Transformation in brief, etc.

Submitted by Monika Sharma, on April 30, 2020

## Computer Graphics | Translations

**Transformation** techniques mean to modify the current shape or object in a particular manner. Changing of an object after creation, in terms of position or even size is known as translation. Here, we will be studying about how 2D translation is performed in computer graphics.

### 2D Translation

The translation is the movement in a straight line of an object from one position to another.

The movement of objects without deforming the shape of the object is Translation. Here the object is shifted from one position to another position and from one co-ordinate location to another.

The translating polygon i.e. all vertex of the polygon is converted to a new position. Similarly, curved objects are translated. To change the position of the circle or ellipse its center coordinates are transformed, then the object is drawn using the new co-ordinates.

**Translation of point:**

To translate a point from coordinate position **(x, y)** to another **(x, y)**, we add algebraically the translation distances **Tx** & **Ty** to the original co-ordinates.

Translation equation:

x1 = x + Tx y1 = y + Ty (The translation pair (Tx, Ty) is called as shift vector)

**Example:**

In the following image you can see that after applying translation, point **C** gets shifted to **C'**.

**Example:**

Given a square with coordinate points A (0, 3), B (3, 3), C (3, 0), D (0, 0). Apply the translation with distance 1 towards X axis and 1 towards Y axis. We have to find the new co-ordinates of the square.

Solution: Given-

Old co-ordinates of the square = A (0, 3), B (3, 3), C (3, 0), D (0, 0)

Translation vector = (Tx, Ty) = (1, 1)

__For Coordinates A (0, 3)__

__For Coordinates A (0, 3)__

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

Applying the translation equations, we have-

- X
_{new}= X_{old}+ T_{x}= 0 + 1 = 1 - Y
_{new}= Y_{old}+ T_{y}= 3 + 1 = 4

Thus, New coordinates of corner A = (1, 4).

**For Coordinates B (3, 3)**

Let the new coordinates of corner B = (X_{new}, Y_{new}).

Applying the translation equations, we have-

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

Thus, New coordinates of corner B = (4, 4).

**For Coordinates C (3, 0)**

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

Applying the translation equations, we have-

- X
_{new}= X_{old}+ T_{x}= 3 + 1 = 4 - Y
_{new}= Y_{old}+ T_{y}= 0 + 1 = 1

Thus, New coordinates of corner C = (4, 1).

**For Coordinates D (0, 0)**

Let the new coordinates of corner D = (X_{new}, Y_{new}).

Applying the translation equations, we have-

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

Thus, New coordinates of corner D = (1, 1).

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.