This post is also available in: العربية (Arabic)

To display a picture of any size on a computer screen is a difficult process. Computer graphics are used to simplify this process. Various algorithms and techniques are used to generate graphics in computers. In this article, we will see how all these are processed by the computer using 2D transformation in computer graphics to give a rich visual experience to the user.

So, let’s understand what is 2D transformation in computer graphics.

## What is Computer Graphics?

Today, 2D transformation in computer graphics is a core technology in digital photography, film, video games, cell phone and computer displays, and many specialized applications. A great deal of specialized hardware and software has been developed, with the displays of most devices being driven by computer graphics hardware.

2D transformation in computer graphics is the art of drawing pictures on computer screens with the help of programming. It involves computations, creation, and manipulation of data. In other words, we can say that computer graphics is a rendering tool for the generation and manipulation of images.

The phrase was coined in 1960 by computer graphics researchers Verne Hudson and William Fetter of Boeing. It is often abbreviated as CG, or in the context of the film as computer-generated imagery (CGI).

Computer graphics is responsible for displaying art and image data effectively and meaningfully to the consumer. It is also used for processing image data received from the physical world, such as photo and video content. Computer graphics development has had a significant impact on many types of media and has revolutionized animation, movies, advertising, video games, etc.

## 2D Transformation in Computer Graphics

2D transformation in computer graphics means changing some graphics into something else by applying rules similar to graph transformations of functions. We can have various types of 2D transformation in computer graphics such as translation, scaling up or down, rotation, shearing, etc. When a transformation takes place on a 2D plane, it is called a 2D transformation.

2D transformation in computer graphics plays an important role in computer graphics to reposition the graphics on the screen and changing their size or orientation.

2D transformation in computer graphics takes place in a two-dimensional plane (XY-plane) and is helpful in changing the position, size, orientation, shape, etc., of the object.

## Transformation Techniques in 2D Transformation in Computer Graphics

In computer graphics, the various techniques used in transformation are:

- Translation
- Rotation
- Scaling
- Reflection
- Shear

### 1. Two Dimensional Transformation in Computer Graphics – Translation

The translation is one of the simplest 2D transformation in computer graphics. A translation moves all points of an object a fixed distance in a specified direction. It can also be expressed in terms of two frames by expressing the coordinate system of the object in terms of translated frames.

It can be described as a rigid motion. A translation can also be interpreted as the addition of a constant vector to every point, or as shifting the origin of the coordinate system.

Suppose, If the point (X, Y) is to be translated by amount Dx and Dy to a new location (X’, Y’) then new coordinates can be obtained by adding Dx to X and Dy to Y as:

X’ = X + Dx

Y’ = Y + Dy

Or, P’ = T + P where

P’ = (X’, Y’), T = (Dx, Dy) and P = (X, Y)

Here, P(X, Y) is the original point. T(Dx, Dy) is the translation factor or shift factor, i.e. the amount by which the point will be translated. P'(X’, Y’) is the coordinates of point P after translation.

### 2. Two Dimensional Transformation in Computer Graphics – Rotation

It is a process of changing the angle of the object. Rotation can be clockwise or anticlockwise. For rotation, we have to specify the angle of rotation and rotation point. A rotation point is also called a pivot point. It is the point at which an object is rotated.

An object can be rotated in any of these two ways – Clockwise and Anti-Clockwise (Counter Clockwise)

The positive value of the pivot point (rotation angle) rotates an object in a counter-clockwise (anti-clockwise) direction. The negative value of the pivot point (rotation angle) rotates an object in a clockwise direction.

When the object is rotated, then every point of the object is rotated by the same angle.

**Straight Line:** Straight Line is rotated by the endpoints with the same angle and redraw the line between new endpoints.

**Polygon:** Polygon is rotated by shifting every vertex using the same rotational angle.

**Curved Lines:** Curved Lines are rotated by repositioning all points and drawing the curve at new positions.

**Circle:** It can be obtained by center position by the specified angle.

**Ellipse:** Its rotation can be obtained by rotating the major and minor axis of an ellipse by the desired angle.

In the rotation, we rotate the object at a particular angle θ (theta), from its origin. In the figure P(X, Y) is located at an angle ɸ from the horizontal X coordinate with distance r from the origin. After rotating it to a new location, we will get a new position P’(X’, Y’).

Using the standard trigonometry, the original coordinates of P(X, Y) can be represented as:

X = r cos ɸ —————————— (1)

Y = r sin ɸ —————————— (2)

Similarly, the point P’(X’, Y’) can be represented as:

X’ = r cos(θ + ɸ) = r cosθ cosɸ – r sinθ sinɸ —————————- (3)

Y’ = r sin(θ + ɸ) = r sinθ cosɸ – r cosθ sinɸ —————————- (4)

Substituting (1) & (2) in (3) & (4)

X’ = Xcosθ – Ysinθ

Y’ = Xsinθ + Ycosθ

### 3. Two Dimensional Transformation in Computer Graphics – Scaling

Scaling is a process of modifying or we can say changing the size of objects. It is a type of transformation through which we can zoom in or zoom out on any particular object or shape.

Scaling can be defined as the process of expanding or compressing the dimension of an object. Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the desired result.

Let us assume that the original coordinates are X and Y, the scaling factors are (S_{X}, S_{Y}) and the produced coordinates are X’ and Y’. This can be mathematically represented as shown below −

X’ = X.S_{X} and Y’ = Y.S_{Y}

The scaling factor S_{X}, S_{Y} scales the object in X and Y direction respectively. If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide values greater than 1, then we can increase the size of the object.

- If S
_{X}> 1 and S_{Y}> 1, then the object is enlarged along both X-axis and Y-axis. - If S
_{X}> 1 and S_{Y}< 1, then the object is enlarged along the X-axis and diminished along the Y-axis. - If S
_{X}< 1 and S_{Y}> 1, then the object is diminished along the X-axis and enlarged along the Y-axis. - If S
_{X}< 1 and S_{Y}< 1, then the object is diminished along both X-axis and Y-axis.

### 4. Two Dimensional Transformation in Computer Graphics – Reflection

Reflection is the mirror image of the original object. In other words, we can say that it is a rotation operation with 180°. In reflection transformation, the size of the object does not change.

The reflection can be of one of two types – about the X-axis, about the Y-axis, about the origin, and about any given line.

**Reflection about X-axis:** If P(x, y) is the point on the x-y plane then P’(x’, y’) is the reflection about the x-axis given as x’ = x ; y’ = -y. Hence, the reflection of a point P(x, y) about the X-axis is P’(x, -y).

**Reflection about Y-axis:** If P(x, y) is the point on the x-y plane then P’(x’, y’) is the reflection about the y-axis given as x’ = -x ; y’ = y. Hence, the reflection of a point P(x, y) about the Y-axis is P’(-x, y).

**Reflection about origin:** If P(x, y) is the point on the x-y plane then P’(x’, y’) is the reflection about the origin given as x’ = -x ; y’ = -y. Hence, the reflection of a point P(x, y) about the origin is P’(-x, -y).

**Reflection about a line:** If P(x, y) is the point on the x-y plane then P’(x’, y’) is the reflection about the line x = y given as x’ = x ; y’ = -y. Hence, the reflection of a point P(x, y) about the X-axis is P’(x, y).

### 5. Two Dimensional Transformation in Computer Graphics – Shear

A 2D transformation in computer graphics that slants the shape of an object is called the shear transformation. There are two shear transformations – X-Shear and Y-Shear. One shifts X coordinates values and the other shifts Y coordinates values. However; in both cases, only one coordinate changes its coordinates and the other preserves its values. Shearing is also termed Skewing.

**X-Shear**: The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines to tilt right or left as shown in the figure below.

**Y-Shear**: The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to transform into lines that slope up or down as shown in the following figure.

## 2D Composite Transformation in Computer Graphics

If a 2D transformation in computer graphics of the plane T1 is followed by a second plane transformation T2, then the result itself may be represented by a single transformation T which is the composition of T1 and T2 taken in that order. This is written as T = T1∙T2.

In general, a composite transformation T = T1.T2.T3. … Tn, where T1, T2, T3, …, Tn are transformations that can be either of the following:

- Translation
- Scaling
- Rotation
- Reflection
- Shearing

## Application of Computer Graphics

Computer Graphics has numerous applications, some of which are listed:

- Graphics User Interfaces (GUIs): A graphic, mouse-oriented approach which allows the user to interact with a computer.
- Graphics in Business Presentations:
- Cartography: Drawing maps, weather maps
- Satellite Imaging: Geodesic images
- Photo Enhancement: Sharpening, etc. of blurred photos.
- Medical Imaging: MRIs, CAT Scans, etc.
- Engineering Drawings – Mechanical, Electrical, Civil, Architectural, etc. – Replacing the blueprints of the past.
- Typography − The use of character images in publishing – replacing the hard type of the past.
- Architecture − Construction plans, exterior sketches – replacing the blueprints and hand drawings of the past.
- Art − Computers provide a new medium for artists.
- Training − Flight simulators, computer-aided instruction, etc.
- Entertainment − Movies and games.
- Simulation and modeling − Replacing physical modeling and enactments.

## Practice Problems

- What is meant by computer graphics?
- What is meant by a 2D transformation in computer graphics?
- What is a translation in 2D transformation?
- What is rotation in 2D transformation?
- What is scaling in 2D transformation?
- What is a reflection in 2D transformation?
- What is shear in 2D transformation?

## FAQs

### What are the types of 2D transformation?

There are 5 types of 2D transformations. These are

a. translation

b. rotation

c. scaling

d. reflection

e. shear

### What do you mean by 2D transformation explain 2D rotation.

2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane. Consider a point object O has to be rotated from one angle to another in a 2D plane. Let- Initial coordinates of the object O = (Xold, Yold) Initial angle of the object O with respect to origin = Φ.

### Where is 2D transformation used?

2D transformation in computer graphics takes place in a two-dimensional plane (XY-plane) and is helpful in changing the position, size, orientation, shape, etc., of the object.

## Conclusion

2D transformation in computer graphics is a core technology in digital photography, film, video games, cell phone and computer displays, and many specialized applications. There are 5 basic types of 2D transformation in computer graphics. These are translation, rotation, scaling, reflection, and shear.