# 2D Transformation in Computer Graphics Solved Examples

## Homogeneous Coordinates:

The **Homogeneous Coordinate** is a method to perform certain standard operations on points in Euclidean space that means of matrix multiplications.

Normally, we add a coordinate to the end of the list and make it equal to 1. Thus the two-dimensional

point (**x,y**) becomes(**x,y,1**) in homogeneous coordinates, and the three-dimensional point (**x,y,z**) becomes (**x,y,z,1**)

Homogeneous Coordinates are not Euclidean coordinates, they are the natural coordinates of a different type of geometry called Projective Geometry.

## Translation:

Let us imagine a point P in a 2D plane. Assume that the current position of P is depicted by its co-ordinate (x,y).

Now, if we force P to move Δx distance horizontally and at the same time Δy distance vertically then the changed location of P becomes **(x+Δx, y+Δy)**.

In terms of object transformation, we can say that the original point object p(x,y) has been translated to becomes P'(x’,y’) and the amount of translation applied is the vector

Algebraically,

**x’=x+Δx
y’=y+Δy**

## Rotation:

This transformation is used to rotate the objects about any point in a reference frame. Unlike translation, rotation brings about changes in position as well as orientation. The point about which the object is rotated that is called Pivot point or Rotation point.

**Rotation about Origin :**

Consider a trial case where the pivot point is the origin as shown in Fig:

then the point to be rotated P(x,y) can be represented as

**x=rcosϕ, y=rsinϕ**

where (r, ϕ) is the polar co-ordinate of P. When this point P is rotated through an angle θ in the anti-clockwise direction, the new point P'(x’,y’) becomes,

**x’=rcos(θ+ϕ) y’=rsin(θ+ϕ)**

## Rotation about an Arbitrary Pivot Point:

The pivot point is an arbitrary point P_{p} having coordinates (x_{p}, y_{p}).After rotating P(x,y) through a positive θ angle its new location is x’y'(P’).

Here

**x’=OB
x=OA+AB
x=x**

_{p}+rcos(θ+ϕ) x=x

_{p}+rcosϕcosθ-rsinϕcosθ x=x

_{p}+(x-x

_{p})cosθ-(y-y

_{p})sinθ

**rcosϕ=AC**

rcosϕ=OC-OA

rcosϕ=x-x

rcosϕ=OC-OA

rcosϕ=x-x

_{p}and

**rsinϕ=A’C’**

rsinϕ=OC’-OA’

rsinϕ=y=y

rsinϕ=OC’-OA’

rsinϕ=y=y

_{p}also

**y’=OB’**

y’=OA’+A’B’

y’=y

y’=rcosϕsinθ+rsinϕcosθ

y’=y

y’=OA’+A’B’

y’=y

_{p}+sin(θ+ϕ)y’=rcosϕsinθ+rsinϕcosθ

y’=y

_{p}+(x-x_{p})sinθ+(y-y_{p})cosθ## Scalling:

Scaling is a transformation that changes the size or shape of an object. Scaling origin can be carried out by multiplying the coordinate values (x,y) of each vertex of a polygon, or each endpoint of a line or the centre point and peripheral definition points of closed curves like a circle by scaling factors s_{x} and s_{y} respectively to produce the coordinate (x’,y’).

The mathematical expression for pure scaling is :

## Coordinate Transformations:

Coordinate Transformations Geometric Transformation of 2D objects which are well-defined with respect to a **Global Coordinate System**, that is also called the **World Coordinate System (WCS)**. It is often found convenient to define quantities with respect to a **Local Coordinate System** that is also called **Model Coordinate System** or **User Coordinate System (UCS)**.

While the UCS may vary from entity to entity and as per convenience, the WCS being the master reference system remains fixed for a given display system, So, you first define an object “**locally**“, you can place it in the global system simply by specifying the location of the origin and orientation of the axes of the local system within the global system, then mathematically transforming the point coordinates defining the object from local to the global system. These type of transformations are known as **Transformation of Coordinate System**.

## Affine Transformation:

An affine transformation involving only translation, rotation and reflection preserves the length and angle between two lines. All two-dimensional transformation where each of the transformed coordinates x’ and y’ is a linear function of the original coordinates x & y as:

**x’=A**

y’=A

_{1}x+B_{1}y+C_{1}y’=A

_{2}x+B_{2}y+C_{2}where A

_{1}, B

_{1}, C

_{1}are parameters fixed for a given transformation type.