Skip to main content

2D Transformation

2D Transformation
The 2D transformations are:

1. Translation
2. Scaling
3. Rotation
4. Reflection
5. Shear


1. Translation: Translation is defined as moving the object from one position to another position along straight line path.

We can move the objects based on translation distances along x and y axis. tx denotes translation distance along x-axis and ty denotes translation distance along y axis.


2. Scaling: Scaling refers to changing the size of the object either by increasing or decreasing. We will increase or decrease the size of the object based on scaling factors along x and y-axis.

If (x, y) are old coordinates of object, then new coordinates of object after applying scaling transformation are obtained as:

x’=x*sx
y’=y*sy.

sx and sy are scaling factors along x-axis and y-axis.


3. Rotation: A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. We rotate an object by an angle theta.
New coordinates after rotation depend on both x and y

• x’ = xcosθ -y sinθ
• y’ = xsinθ+ ycosθ



4. Reflection: Reflection is nothing but producing mirror image of an object. Reflection can be done just by rotating the object about given axis of reflection with an angle of 180 degrees.


5. Shear:


1. Shear is the translation along an axis by an amount that increases linearly with another axis (Y). It produces shape distortions as if objects were composed of layers that are caused to slide over each other.

2. Shear transformations are very useful in creating italic letters and slanted letters from regular letters.

3. Shear transformation changes the shape of the object to a slant position.

4. Shear transformation is of 2 types:

a. X-shear: changing x-coordinate value and keeping y constant

x’=x+shx*y
y’=y

b. Y-shear: changing y coordinates value and keeping x constant

x’=x
y’=y+shy*x

shx and shy are shear factors along x and y-axis.





Code:

If you can't see the code, then Enable JavaScript in you browser


Output:

Translation:
 


Rotation:
 


Scaling:
 


Reflection:
 
 


Shear:
 
 



Note: Just copy the files "CGA.bgi" & "EGAVGA.bgi" from bgi folder to bin. So, if you have copied these 2 files then you can skip writing "C:\\tc\\bgi" in initgraph with just ""(2 double quotes)

Comments

Post a Comment

Popular posts from this blog

Bresenham's Line Algorithm (THICK LINE)

Bresenham's Line Algorithm (THICK LINE) Bresenham's Line Algorithm (THICK LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DASHED LINE)

Bresenham's Line Algorithm (DASHED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DOTTED LINE)

Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.



Bestseller's in Electronics only at Amazon Best Selling Products on Amazon