0% found this document useful (0 votes)
7 views7 pages

Transformation Lab5

The document outlines a lab report for a Computer Graphics and Visualization course at Tribhuvan University, focusing on basic transformations such as translation, rotation, and scaling of shapes using matrix operations. It includes objectives, theoretical background, an algorithm, source code, and conclusions about the practical applications of geometric transformations. The lab emphasizes the importance of linear algebra in manipulating points and shapes in two-dimensional space.

Uploaded by

luciferparajulee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Transformation Lab5

The document outlines a lab report for a Computer Graphics and Visualization course at Tribhuvan University, focusing on basic transformations such as translation, rotation, and scaling of shapes using matrix operations. It includes objectives, theoretical background, an algorithm, source code, and conclusions about the practical applications of geometric transformations. The lab emphasizes the importance of linear algebra in manipulating points and shapes in two-dimensional space.

Uploaded by

luciferparajulee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Tribhuvan University

Institute of Engineering
Thapathali Campus, Thapathali

Subject: Computer Graphics and Visualization


LAB #5

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>

#include <cmath> rotmat[0][1] = -std::sin(angle);

rotmat[0][2] = 0;

void setmatrix(float a[3][3], float b[3][3]){ rotmat[1][0] = std::sin(angle);

a[0][0] = b[0][0]; rotmat[1][1] = std::cos(angle);

a[0][1] = b[0][1]; rotmat[1][2] = 0;

a[0][2] = b[0][2]; rotmat[2][0] = 0;

a[1][0] = b[1][0]; rotmat[2][1] = 0;

a[1][1] = b[1][1]; rotmat[2][2] = 1;

a[1][2] = b[1][2]; multmatrix(p, rotmat);

a[2][0] = b[2][0]; }

a[2][1] = b[2][1];

a[2][2] = b[2][2]; void translate(float p[3][3], float x, float y){

} float tmat[3][3];

tmat[0][0] = 1;

void multmatrix(float a[3][3], float b[3][3]){

float result[3][3]; tmat[0][1] = 0;

for(int i = 0; i<3;i++){ tmat[0][2] = x;

for(int j = 0; j <3;j++){ tmat[1][0] = 0;

result[i][j] = 0; tmat[1][1] = 1;

for(int k = 0; k<3;k++){ tmat[1][2] = y;

result[i][j] += a[i][k] * b[k][j]; tmat[2][0] = 0;

tmat[2][1] = 0;

} tmat[2][2] = 1;

std::cout<<result[i][j]<<" "; multmatrix(p, tmat);

} }

std::cout<<std::endl; void scale(float p[3][3], float x, float y){

} float smat[3][3];

setmatrix(a,result); smat[0][0] = x;

void rotate(float p[3][3], float angle){ smat[0][1] = 0;

float rotmat[3][3]; smat[0][2] = 0;


smat[1][0] = 0; points[0][1] = x2;

smat[1][1] = y; points[1][1] = y2;

smat[1][2] = 0; points[2][1] = 1;

smat[2][0] = 0; points[0][2] = x3;

smat[2][1] = 0; points[1][2] = y3;

smat[2][2] = 1; points[2][2] = 1;

multmatrix(p, smat); float tx,ty;

} float angle;

int main(){ float sx, sy;

float cm[3][3]; std::cout<<"ENTER TRANSLATION X AND Y: ";

cm[0][0] = 1; std::cin>>tx>>ty;

cm[0][1] = 0; std::cout<<"ENTER ROTATION ANGLE: ";

cm[0][2] = 0; std::cin>>angle;

cm[1][0] = 0; angle = (3.14/180)*angle;

cm[1][1] = 1; std::cout<<"ENTER SCALE X AND Y: ";

cm[1][2] = 0; std::cin>>sx>>sy;

cm[2][0] = 0;

cm[2][1] = 0; outtextxy(points[0][0], points[1][0], "PRANJAL


SHRESTHA");
cm[2][2] = 1;

int gd = DETECT, gm;


line(points[0][0], points[1][0],points[0][1],points[1][1]);
initgraph(&gd,&gm, NULL);
line(points[0][1], points[1][1],points[0][2],points[1][2]);
float x1,y1,x2,y2,x3,y3;
line(points[0][2], points[1][2],points[0][0],points[1][0]);
std::cout<<"ENTER X AND Y OF FIRST POINT OF
TRIANGLE: ";

std::cin>>x1>>y1; translate(cm, tx,ty);

std::cout<<"ENTER X AND Y OF SECOND POINT OF rotate(cm, angle);


TRIANGLE: ";
scale(cm, sx,sy);
std::cin>>x2>>y2;
multmatrix(cm, points);
std::cout<<"ENTER X AND Y OF THIRD POINT OF
TRIANGLE: ";

std::cin>>x3>>y3; line(cm[0][0], cm[1][0],cm[0][1],cm[1][1]);

float points[3][3]; line(cm[0][1], cm[1][1],cm[0][2],cm[1][2]);

points[0][0] = x1; line(cm[0][2], cm[1][2],cm[0][0],cm[1][0]);

points[1][0] = y1; getch();

points[2][0] = 1; closegraph();
}

Output:

Fig: Input and Corresponding Matrix Results


Fig: Output Before and After Transformation

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.

You might also like