AIM

To write a C program to implement 3D transformations.
ALGORITHM
1.
2.
3.
4.
5.

Enter the choice for transformation.
Perform the translation, rotation, scaling of 3D object.
Get the needed parameters for the transformation from the user.
Increase of rotation, object can be rotated about x or y or z axis.
Display the transmitted object in the screen

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int maxx,maxy,midx,midy;
void axis()
{
getch();
cleardevice();
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
}
void main()
{
int gd,gm,x,y,z,o,x1,x2,y1,y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"d:\\tc\\bgi");
setfillstyle(0,getmaxcolor());
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
axis();
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);
printf("\Enter the translation factor");
scanf("%d%d",&x,&y);
axis();
printf("After translation");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);
bar3d(midx+x+100,midy-(y+150),midx+x+60,midy-(y+100),10,1);
axis();

scanf("%d%d%d".midy-(y*150). axis(). axis().1).midy-150.midy-100. x2=60*cos(o*3. axis(). bar3d(midx+100.14/180).1).midy-100. printf("After rotating about x -axis").midy-x1. closegraph(). bar3d(midx+x1.midx+60.midx+60.10*z.1).midx+(x*60).midy-y2. bar3d(midx+100. x1=50*cos(o*3. y1=50*sin(o*3.midx+x2.10. } OUTPUT RESULT Thus the c program to implement 3D transformations was coded and executed successfully.10. .midy-y1.midy-100.midy-150.14/180).1). printf("Enter the scaling factor").midy-x2.14/180).midy-150.1).10.10.midx+60. printf("After rotating about Y-axis").&o).14/180).midx+60.&y.midy-100.midy-150.1).14/180)+90*cos(o*3.midx+x2.10.14/180)-90*sin(o*3.10.10. printf("After scaling").&z). bar3d(midx+100.10. axis(). y2=60*sin(o*3.midx+60. bar3d(midx+100.midy-100.midy-(y*100).1). printf("After rotating about Z-axis").&x.14/180)+100*cos(o*3. axis().midy-100.midx+60. printf("Enter the rotation angle"). getch(). bar3d(midx+x1. bar3d(midx+100. bar3d(midx+100.1).1).bar3d(midx+100.14/180)-100*sin(o*3.midy-100.10.1).midy-150.midx+60.midy-150. bar3d(midx+(x*100). scanf("%d".midy-150.

Sign up to vote on this title
UsefulNot useful