0% found this document useful (0 votes)
8 views2 pages

P9:Design A Program To Translate A Polygon. Name:-Aashish Pandey Date:3-04-24 Source Code

The document describes a program to translate a polygon by scaling, rotating, and translating it. The program takes vertex coordinates of a polygon as input, performs the transformations using matrix multiplication, and displays the original and transformed polygons.

Uploaded by

Aashish Pandey
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)
8 views2 pages

P9:Design A Program To Translate A Polygon. Name:-Aashish Pandey Date:3-04-24 Source Code

The document describes a program to translate a polygon by scaling, rotating, and translating it. The program takes vertex coordinates of a polygon as input, performs the transformations using matrix multiplication, and displays the original and transformed polygons.

Uploaded by

Aashish Pandey
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/ 2

P9:Design a program to translate a polygon.

Name:-Aashish Pandey Date:3-04-24


Source Code
#include<iostream.h>
#include<graphics.h> outtextxy(500,50,"Transformed");
#include<math.h>
#include<conio.h> for(i=0;i<n-1;i++)
#include<dos.h> {
void mul(int mat[3][3],int line(320+vertex[i][0],240-
vertex[10][3],int n); vertex[i][1],320+vertex[i+1]
void scale(int vertex[10][3],int [0],240-vertex[i+1][1]);
n); }
void init(int vertex[10][3],int line(320+vertex[n-1][0],240-
n); vertex[n-1][1],320+vertex[0]
int main() [0],240-vertex[0][1]);
{
int i,x,y; }
int vertex[10][3],n;
clrscr(); void mul(int mat[3][3],int
cout<<"\nEnter the no. of vertex[10][3],int n)
vertex : "; {
cin>>n; int i,j,k;
for(i=0;i<n;i++)
{
cout<<"Enter the points int res[10][3];
(x,y): "; for(i=0;i<n;i++)
cin>>x>>y; {
vertex[i][0]=x; for(j=0;j<3;j++)
vertex[i][1]=y; {
vertex[i][2]=1; res[i][j]=0;
} for(k=0;k<3;k++)
{
scale(vertex,n); res[i][j] = res[i]
[j] + vertex[i][k]*mat[k][j];
getch(); }
return 0; }
} }

void init(int vertex[10][3],int n) setcolor(15);


{ for(i=0;i<n-1;i++)
{
int gd=DETECT,gm,i; line(320+res[i][0],240-
initgraph(&gd,&gm,"C:\\ res[i][1],320+res[i+1][0],240-
turboc3\\bgi"); res[i+1][1]);
}
line(320+res[n-1][0],240-
setcolor(15); res[n-1][1],320+res[0][0],240-
line(0,240,640,240); res[0][1]);
line(320,0,320,480);
}

setcolor(15); void scale(int vertex[10][3],int


line(450,20,490,20); n)
setcolor(15); {
line(450,50,490,50);
setcolor(15); int scale_array[3][3];
setcolor(15);
outtextxy(500,20,"Original"); int x,y;
cout<<"\nEnter scale factor in scale_array[2][1]=0;
X direction: "; scale_array[0][2]=0;
cin>>x; scale_array[1][2]=0;
cout<<"Enter scale factor in Y scale_array[2][2]=1;
direction: ";
cin>>y;
scale_array[0][0]=x; init(vertex,n);
scale_array[1][0]=0;
scale_array[2][0]=0;
scale_array[0][1]=0;
scale_array[1][1]=y;
mul(scale_array,vertex,n);}

Output:

You might also like