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

Practical 9

The document describes a program to translate a polygon by taking user input for the number of vertices and their x,y coordinates, initializing a graphics screen, drawing the original polygon, getting scale factors from the user, applying a scale transformation matrix to the vertices, and redrawing the scaled polygon.

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)
25 views2 pages

Practical 9

The document describes a program to translate a polygon by taking user input for the number of vertices and their x,y coordinates, initializing a graphics screen, drawing the original polygon, getting scale factors from the user, applying a scale transformation matrix to the vertices, and redrawing the scaled polygon.

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:- Harsh Madankar


Date: 3-04-24
line(450,50,490,50);
#include<iostream.h> setcolor(15);
#include<graphics.h> setcolor(15);
#include<math.h> outtextxy(500,20,"Original");
#include<conio.h> outtextxy(500,50,"Transformed");
#include<dos.h>
for(i=0;i<n-1;i++)
void mul(int mat[3][3],int vertex[10][3],int n); {
void scale(int vertex[10][3],int n); line(320+vertex[i][0],240-vertex[i]
void init(int vertex[10][3],int n); [1],320+vertex[i+1][0],240-vertex[i+1][1]);
}
int main() line(320+vertex[n-1][0],240-vertex[n-1]
{ [1],320+vertex[0][0],240-vertex[0][1]);
int i,x,y;
int vertex[10][3],n; }
clrscr();
cout<<"\nEnter the no. of vertex : "; void mul(int mat[3][3],int vertex[10][3],int n)
cin>>n; {
for(i=0;i<n;i++) int i,j,k;
{
cout<<"Enter the points (x,y): ";
cin>>x>>y; int res[10][3];
vertex[i][0]=x; for(i=0;i<n;i++)
vertex[i][1]=y; {
vertex[i][2]=1; for(j=0;j<3;j++)
} {
res[i][j]=0;
scale(vertex,n); for(k=0;k<3;k++)
{
getch(); res[i][j] = res[i][j] + vertex[i]
return 0; [k]*mat[k][j];
} }
}
void init(int vertex[10][3],int n) }
{
setcolor(15);
int gd=DETECT,gm,i; for(i=0;i<n-1;i++)
initgraph(&gd,&gm,"C:\\turboc3\\bgi"); {
line(320+res[i][0],240-res[i]
[1],320+res[i+1][0],240-res[i+1][1]);
setcolor(15); }
line(0,240,640,240); line(320+res[n-1][0],240-res[n-1]
line(320,0,320,480); [1],320+res[0][0],240-res[0][1]);

}
setcolor(15);
line(450,20,490,20); void scale(int vertex[10][3],int n)
setcolor(15); {
int scale_array[3][3];

int x,y;
cout<<"\nEnter scale factor in X direction: ";
cin>>x;
cout<<"Enter scale factor in Y direction: ";
cin>>y;
scale_array[0][0]=x;
scale_array[1][0]=0;
scale_array[2][0]=0;
scale_array[0][1]=0;
scale_array[1][1]=y;
scale_array[2][1]=0;
scale_array[0][2]=0;
scale_array[1][2]=0;
scale_array[2][2]=1;

init(vertex,n);

mul(scale_array,vertex,n);}

Output:

You might also like