0% found this document useful (0 votes)
28 views6 pages

Basic Transformations

The document is a C++ program that implements basic geometric transformations such as scaling, translation, and rotation for a polygon using operator overloading. It defines a class 'Transformation' with methods to draw a polygon and perform the transformations based on user input. The program utilizes the graphics library to visualize the transformations and runs in a loop until the user chooses to exit.

Uploaded by

aryanhiremath14
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)
28 views6 pages

Basic Transformations

The document is a C++ program that implements basic geometric transformations such as scaling, translation, and rotation for a polygon using operator overloading. It defines a class 'Transformation' with methods to draw a polygon and perform the transformations based on user input. The program utilizes the graphics library to visualize the transformations and runs in a loop until the user chooses to exit.

Uploaded by

aryanhiremath14
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

#include<iostream>

#include<graphics.h>

#include<math.h>

using namespace std;

int object[4][3]={{100,100,1},{200,100,1},{200,200,1},{100,200,1}};

class Transformation

public:

void drawPolygon(int [4][3]);

void operator ! (); //scaling

void operator - (); //translation

void operator + (); //Clockwise

void operator * (); //Anti Clockwise

// ~Transformation();

};

void Transformation::drawPolygon(int poly[4][3])

int i;

for (i=0;i<3;i++)

line(poly[i][0],poly[i][1],poly[i+1][0],poly[i+1][1]);

line(poly[i][0],poly[i][1],poly[0][0],poly[0][1]);

}
//scaling

void Transformation :: operator ! ()

int result[4][3];

int sx=2, sy=2;

for(int i=0;i<=3;i++)

result[i][0]=object[i][0]*sx;

result[i][1]=object[i][1]*sy;

drawPolygon(result);

// translation

void Transformation :: operator - ()

int result[4][3];

int tx=80, ty=80;

for(int i=0;i<=3;i++)

result[i][0]=object[i][0]+tx;

result[i][1]=object[i][1]+ty;

drawPolygon(result);

}
// rotation anticlockwise

void Transformation :: operator * ()

int result[4][3];

int ang=10;

double angle=(ang * (3.14/180));

for(int i=0;i<=3;i++)

result[i][0]=object[i][0]*cos(angle)+object[i][1]*sin(angle);

result[i][1]=-object[i][0]*sin(angle)+object[i][1]*cos(angle);

drawPolygon(result);

// rotation clockwise

void Transformation :: operator + ()

int result[4][3];

int ang=10;

double angle=(ang * (3.14/180));

for(int i=0;i<=3;i++)

result[i][0]=object[i][0]*cos(angle)-object[i][1]*sin(angle);

result[i][1]=object[i][0]*sin(angle)+object[i][1]*cos(angle);
}

drawPolygon(result);

int main()

int gd = DETECT, gm,choice;

initgraph(&gd, &gm, NULL);

Transformation t;

[Link](object);

delay(5000);

do{

cleardevice();

cout<<"\n1) Scaling";

cout<<"\n2) Translation";

cout<<"\n3) Clockwise Rotation";

cout<<"\n4) Anti Clockwise Rotation";

cout<<"\n5) Exit";

cout<<"\n Enter your choice :: ";

cin>>choice;

switch(choice)

case 1:

setcolor(WHITE);

[Link](object);

setcolor(MAGENTA);
!t;

delay(5000);

cleardevice();

break;

case 2:

setcolor(WHITE);

[Link](object);

setcolor(GREEN);

-t;

delay(5000);

cleardevice();

break;

case 3:

setcolor(WHITE);

[Link](object);

setcolor(YELLOW);

*t;

delay(5000);

cleardevice();

break;

case 4:

setcolor(WHITE);

[Link](object);

setcolor(CYAN);

+t;

delay(5000);

cleardevice();

break;
case 5:

break;

default :

cout<<"\nEnter correct choice.....";

}while(choice!=5);

You might also like