Transformation Lab5
Transformation Lab5
Institute of Engineering
Thapathali Campus, Thapathali
Submitted By:
Name: Pranjal Shrestha
Roll No.: THA080BEI033
Submitted To:
Department of Electronics and Computer Engineering
Submission Date: 15th January, 2025
TITLE: BASIC TRANSFORMATION
Objective:
To understand and implement the basic transformations of a shape.
Theory:
A transformation is represented as a matrix, and applying the transformation involves multiplying this
matrix by a vector (or another matrix) that represents the object being transformed.
If A is a transformation matrix and v is a vector, then the transformed vector v′ is computed as:
v′=A⋅v
Translation Matrix:
Rotation Matrix:
Scaling Matrix:
Algorithm:
Step 1: Start
Step 2: Declare Composite Matrix cm as identity matrix
Step 3: Input points for triangle
Step 4: Store points in a matrix
Step 5 Input Translation factor, Rotation angle and Scaling factor
Step 6: Multiply Composite Matrix with Translation, Rotation and Scaling matrices
Step 7: Display Triangle without Transformation
Step 8: Multiply Composite Matrix with Points Matrix
Step 9: Display Triangle after Transformation
Step 10: Stop
Source Code:
#include <graphics.h> rotmat[0][0] = std::cos(angle);
#include <iostream>
rotmat[0][2] = 0;
a[2][0] = b[2][0]; }
a[2][1] = b[2][1];
} float tmat[3][3];
tmat[0][0] = 1;
result[i][j] = 0; tmat[1][1] = 1;
tmat[2][1] = 0;
} tmat[2][2] = 1;
} }
} float smat[3][3];
setmatrix(a,result); smat[0][0] = x;
smat[1][2] = 0; points[2][1] = 1;
smat[2][2] = 1; points[2][2] = 1;
} float angle;
cm[0][0] = 1; std::cin>>tx>>ty;
cm[0][2] = 0; std::cin>>angle;
cm[1][2] = 0; std::cin>>sx>>sy;
cm[2][0] = 0;
points[2][0] = 1; closegraph();
}
Output:
Conclusion:
In this lab, we explored the mathematical principles and practical applications of geometric
transformations, including translation, scaling and rotation. Using transformation matrices, we
demonstrated how points and shapes can be manipulated in two-dimensional space. The lab provided
hands-on experience with transformation algorithms and reinforced the importance of linear algebra in
computational tasks. Future work could involve applying these concepts to more complex systems,
such as 3D object rendering or real-time animation.