Simple GUI Notepad Using Ruby

GUI Notepad Using Ruby Code require 'tk' class Notepad def saveFile file = File.open("note", "w") ...

Wednesday, March 2, 2016

Basic Transformations In Computer Graphics

Basic Transformation methods

Aim
To implement set of basic transformations on polygon i.e. Translation, Rotation, Scaling, Reflection and Shearing
Pre-requisite:
Knowledge of matrix fundamentals and basic transformations on polygon i.e. translation, rotation, scaling, reflection and shearing.
Description
Transformations allows us to uniformly alter the entire picture. The geometric transformations considered here - translation, scaling and rotation are expressed in terms of matrix multiplication. Homogeneous coordinates are considered to uniformly treat the translations

Scaling Transformation

A 2D point can be scaled by multiplication of the coordinate values (x,y) by scaling factors Sx and Sy to produce the transformed coordinates (x',y').

Matrix format: [X'] = [S]x[X]
Where [X']- Transformed Matrix; 
[X]- Point or Object Matrix; and 
[S]- Scaling Matrix

[x1' x2' x3']   [sx 0 0]   [x1 x2 x3]  
[y1' y2' y3'] = [0 sy 0] x [y1 y2 y3]
[1    1   1 ]   [0 0  1]   [1   1  1]

Translation Transformation

A 2D point can be translated by adding the coordinate values (x,y) by Translation distances tx and ty to produce the transformed coordinates (x',y').

Matrix format: [X'] = [T]x[X]
Where [X']- Transformed Matrix; 
[X]- Point or Object Matrix; and 
[T]- Translation Matrix

[x1' x2' x3']   [1 0 tx]   [x1 x2 x3]  
[y1' y2' y3'] = [0 1 ty] x [y1 y2 y3]
[1    1   1 ]   [0 0  1]   [1   1  1]

Rotaion Transformation

A 2D point can be rotated by re-positioning it along a circular path in the xy plane. We specify the rotation angle and the position of the rotation point about which the object is to be rotated. Multiplication of the coordinate values (x,y) by rotation matrix produce the transformed coordinates (x',y').

Matrix format: [X'] = [R]x[X]
Where [X']- Transformed Matrix; 
[X]- Point or Object Matrix; and 
[R]- Rotation Matrix


[x1' x2' x3']   [cos(Θ) -sin(Θ) 0]   [x1 x2 x3]    
[y1' y2' y3'] = [sin(Θ)  cos(Θ) 0] x [y1 y2 y3]  
[1    1   1 ]   [0          0   1]   [1   1  1]