0% found this document useful (0 votes)
16 views7 pages

Exp Eight

experiment 8

Uploaded by

sayedzubia2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Exp Eight

experiment 8

Uploaded by

sayedzubia2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment No.

8: 3D Transformation

Aim: Implement program to perform 3D Transformation.


Theory:
3D Geometry
Three dimension system has three axis x, y, z. The orientation of a 3D coordinate system
is of two types. Right-handed system and left-handed system.
In the right -handed system thumb of right- hand points to positive z-direction and left-
hand system thumb point to negative two directions. Following figure show right-hand
orientation of the cube.
The 2D can show two-dimensional objects. Like the Bar chart, pie chart, graphs. But
some more natural objects can be represented using 3D. Using 3D, we can see different
shapes of the object in different sections.

Rotation:
3D rotation is not same as 2D rotation. In 3D rotation, we have to specify the angle of
rotation along with the axis of rotation. We can perform 3D rotation about X, Y, and Z
axes.

Scaling:
You can change the size of an object using scaling transformation. In the scaling process,
you either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.

Shear:
A transformation that slants the shape of an object is called the shear transformation. Like
in 2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D.
Algorithm:
3 Dimensional Transformation Source Code
1. Enter the choice for transformation.
2. Perform the translation, rotation, scaling of 3D object.
3. Get the needed parameters for the transformation from the user.
4. Increase of rotation, object can be rotated about x or y or z axis.
5. 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,ang,x1,x2,y1,y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:/Turboc3/BGI");
setfillstyle(3,25);
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
outtextxy(100,100,"ORIGINAL OBJECT");
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
axis();
outtextxy(100,20,"TRANSLATION");
printf("\n\n Enter the Translation vector: ");
scanf("%d%d",&x,&y);
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+(x+100),midy-(y+20),midx+(x+60),midy-(y+90),20,5);
axis();
outtextxy(100,20,"SCALING");
printf("\n Enter the Scaling Factor: ");
scanf("%d%d%d",&x,&y,&z);
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+(x*100),midy-(y*20),midx+(x*60),midy-(y*90),20*z,5);
axis();
outtextxy(100,20,"ROTATION");
printf("\n Enter the Rotation angle: ");
scanf("%d",&ang);
x1=100*cos(ang*3.14/180)-20*sin(ang*3.14/180);
y1=100*sin(ang*3.14/180)+20*sin(ang*3.14/180);
x2=60*cos(ang*3.14/180)-90*sin(ang*3.14/180);
y2=60*sin(ang*3.14/180)+90*sin(ang*3.14/180);
axis();
printf("\n After rotating about z-axis\n");
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,20,5);
axis();
printf("\n After rotating about x-axis\n");
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+100,midy-x1,midx+60,midy-x2,20,5);
axis();
printf("\n After rotating about y-axis\n");
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+x1,midy-20,midx+x2,midy-90,20,5);
axis();
closegraph();
}
Output:
Conclusion: Thus, we have implemented the program of 3D Transformation Using C.

You might also like