2 DIMENSIONAL ROTATION
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
float px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void translation();
void scaling();
void rotation();
int vertices;
void main()
{
int
gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
if(graphresult()!=grOk)
{
printf("Graphics
error");
getch();
return;
}
printf("Enter
number of vertices : ");
scanf("%d",&vertices);
printf("Enter
the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
}
disp1();
rotation();
disp2();
getch();
return;
}
void disp1()
{
int
i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px[vertices-1],py[vertices-1],px[0],py[0]);
}
}
void disp2()
{
int
i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
}
}
void rotation()
{
float
a,rx,ry,dir,s;
int
i;
printf("Enter
the rotation angle : ");
scanf("%f",&a);
printf("Enter
the rotation point coordinates : ");
scanf("%f%f",&rx,&ry);
printf("Enter
the direction of rotation 1 for clockwise and
2 for anticlockwise:");
scanf("%f",&dir);
if(dir==1)
s=1;
else
s=-1;
for(i=0;i<vertices;i++)
{
tx[i]=(rx + (px[i]-rx)*cos(a) -
(py[i]-ry)*sin(a)*s);
ty[i]=(ry + (px[i]-rx)*sin(a)*s +
(py[i]-ry)*cos(a));
}
getch();
}
2 DIMENSIONAL ROTATION
OUTPUT:-
Enter the number of vertices:3
Enter the coordinate 1: 100 200
Enter the coordinate 2: 200 200
Enter the coordinate 3: 200 200
Enter the rotation angle: 90
Enter the rotation point: 200 200
Enter the direction (1.Clockwise 2.Anti Clockwise) :
1
0 comments:
Post a Comment