3D ROTATION
AIM:
To write a
program that implement 3D transformation as rotation
ALGORITHML:
·
Declare
the header file
·
Declare
the variables and values
·
Use
the graphics function create an image to implement the 3D Rotation
·
Image
3D transformation rotation
·
Print
the output of 3D image rotation
CODINGS:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
int main(void)
{
int gd=DETECT,gm;
int
xmax,ymax,tx,ty,tz,i,n;
int
x[20],y[20],z[20],a[20],b[20],ch;
int th,t;
initgraph(&gd,&gm,"
");
xmax=getmaxx();
ymax=getmaxy();
line(xmax/2,0,xmax/2,ymax/2);
line(xmax/2,ymax/2,xmax,ymax/2);
line(xmax/2,ymax/2,0,ymax);
printf("Enter
the number of sides\n");
scanf("%d",&n);
printf("ROTATION\n");
printf("Enter
the co-ordinates:\n");
for(i=0;i<n;i++)
{
scanf("%d%d%d",&x[i],&y[i],&z[i]);
x[i]=x[i]+xmax/2;
y[i]=ymax/2-y[i];
a[i]=x[i]-z[i];
b[i]=y[i]-z[i];
}
for(i=0;i<n;i++)
{
line(x[i],y[i],x[(i+1)%n],y[(i+1)%n]);
line(x[i]-z[i],y[i]-z[i],x[(i+1)%n]-z[(i+1)%n],y[(i+1)%n]-z[(i+1)%n]);
line(x[i],y[i],x[i]-z[i],y[i]-z[i]);
}
printf("Enter
the th values:\n");
scanf("%d",&th);
t=th*(3.14/180);
cleardevice();
line(xmax/2,0,xmax/2,ymax/2);
line(xmax/2,ymax/2,xmax,ymax/2);
line(xmax/2,ymax/2,0,ymax);
for(i=1;i<=n;i++)
{
int
xx=x[i];
x[i]=x[0]+(x[i]-x[0])*cos(t)-(y[i]-y[0])*sin(t);
y[i]=y[0]+(xx-x[0])*sin(t)+(y[i]-y[0])*cos(t);
xx=a[i];
a[i]=a[0]+(a[i]-a[0])*cos(t)-(b[i]-b[0])*sin(t);
b[i]=b[0]+(xx-a[0])*sin(t)+(b[i]-b[0])*cos(t);
}
for(i=0;i<n;i++)
{
line(x[i],y[i],x[(i+1)%n],y[(i+1)%n]);
line(a[i],b[i],a[(i+1)%n],b[(i+1)%n]);
line(x[i],y[i],a[i],b[i]);
}
getch();
closegraph();
return 0;
}
OUTPUT:
Enter the no of sides: 2
ROTATION
Enter the co-ordinates:
10
20
30
40
50
60
Enter the th value:60
RESULT:
Thus, the program has been
successfully executed & output is verified.
No comments:
Post a Comment