#include stdio.h
#include conio.h
#include graphics.h
#include math.h
void scaling();
void rotation();
void display();
int ax[10],ay[10],n;
void main()
{
int i,gd,gm=DETECT,ch;
clrscr();
printf("Enter the number of vertices in the polygon\t");
scanf("%d",&n);
printf("\nEnter the co-ordinates of the vertices");
for(i=0;i
{
printf("\nEnter the x cordinate and y cordinate of point %d\t",i+1);
scanf("%d %d",&ax[i],&ay[i]);
}
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
display();
do
{
printf("\nEnter 1-Scaling 2-Rotation 3-Exit\n");
printf("Enter your choice\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
scaling();
break;
}
case 2:
{
rotation();
break;
}
case 3:
{
exit();
break;
}
}
}while(ch!=4);
getch();
closegraph();
}
void display()
{
int i;
clrscr();
for(i=0;i<(n-1);i++)
{
line(ax[i],ay[i],ax[i+1],ay[i+1]);
}
line(ax[n-1],ay[n-1],ax[0],ay[0]);
}
void scaling()
{
float sx,sy,i;
printf("\nEnter the scaling factors(enter 1 for no scaling)");
scanf("%f %f",&sx,&sy);
for(i=0;i
{
ax[i]=ax[i]*sx;
ay[i]=ay[i]*sy;
}
display();
}
void rotation()
{
int i;
float an;
printf("\nEnter the angle of rotation\t");
scanf("%f",&an);
an=((an*3.142)/180);
for(i=0;i
{
ax[i]=(ax[i]*cos(an))-(ay[i]*sin(an));
ay[i]=(ax[i]*sin(an))+(ay[i]*cos(an));
}
display();
}
No comments:
Post a Comment