3 DIMENSIONAL ROTATION
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float
px[10],py[10],tx[10],ty[10],tx2[10],ty2[10],px2[10],py2[10];
void disp1();
void disp2();
void rotation();
float depth,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("%f",&vertices);
printf("Enter
the depth value : ");
scanf("%f",&depth);
printf("Enter
the x and y coordinates : ");
for(i=0;i<vertices;i++)
{
scanf("%f%f",&px[i],&py[i]);
px2[i]=px[i]+depth;
py2[i]=py[i]+depth;
}
disp1();
rotation();
disp2();
getch();
}
void disp1()
{
int
i;
for(i=0;i<vertices-1;i++)
{
line(px[i],py[i],px[i+1],py[i+1]);
line(px2[i],py2[i],px2[i+1],py2[i+1]);
}
line(px[vertices-1],py[vertices-1],px[0],py[0]);
line(px2[vertices-1],py2[vertices-1],px2[0],py2[0]);
for(i=0;i<vertices;i++)
line(px[i],py[i],px2[i],py2[i]);
}
void disp2()
{
int
i;
for(i=0;i<vertices-1;i++)
{
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx2[i],ty2[i],tx2[i+1],ty2[i+1]);
}
line(tx[vertices-1],ty[vertices-1],tx[0],ty[0]);
line(tx2[vertices-1],ty2[vertices-1],tx2[0],ty2[0]);
for(i=0;i<vertices;i++)
line(tx[i],ty[i],tx2[i],ty2[i]);
}
void rotation()
{
float
i,an,rx,ry,dir,s,a;
printf("Enter
the rotation angle : ");
scanf("%f",&an);
printf("Enter
the rotation point : ");
scanf("%f%f",&rx,&ry);
printf("Enter
the dircetion of rotation [1 for clockwise / 2 for anticlockwise] : ");
scanf("%f",&dir);
if(dir==1)
s=1;
else
s=-1;
a=an*3.14/180;
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);
tx2[i]=rx+(px2[i]-rx)*cos(a)
- (py2[i]-ry)*sin(a)*s;
ty2[i]=ry+(px2[i]-rx)*sin(a)*s
+ (py2[i]-ry)*cos(a);
}
}
3-DIMENSIONAL ROTATION
OUTPUT:
Enter the number of vertices: 3
Enter the depth value : 20
Enter the x and y coordinates : 100
150
150
150
150
100
Enter the rotation angle: 30
Enter the rotation point : 50
50
Enter the direction of rotation
(1-Clockwise, 2-Anticlockwise) : 1
0 comments:
Post a Comment