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

3D Computer Graphics

The document discusses performing 3D transformations including translation, scaling, and rotation of objects using C programming language. It provides the aim, algorithm, program code, and output for translating an object by getting translation values x and y, scaling an object by getting scaling values x, y, and z, and rotating an object about the X, Y, and Z axes by getting a rotating angle. The result is that 3D transformations of translation, scaling, and rotation are successfully achieved for a given object using C.

Uploaded by

Cheems the Great
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)
64 views7 pages

3D Computer Graphics

The document discusses performing 3D transformations including translation, scaling, and rotation of objects using C programming language. It provides the aim, algorithm, program code, and output for translating an object by getting translation values x and y, scaling an object by getting scaling values x, y, and z, and rotating an object about the X, Y, and Z axes by getting a rotating angle. The result is that 3D transformations of translation, scaling, and rotation are successfully achieved for a given object using C.

Uploaded by

Cheems the Great
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
You are on page 1/ 7

3D-TRANSFORMATION [TRANSLATION]

Aim:
To perform translation in 3D transformation using c language.

Algorithm:
1] Initialize the graphics mode.
2] Construct a 3D object.
3] Translation
a) Get the translation value x,y.
b) midx=maxx/2; midy=maxy/2
c) bar3d(midx+50,midy-100,midx+60,midy-90,10,1)
bar3d(midx+x+50,midy-(y+100),midx+x+60,midy-(y+90),10,1)
4] Execute the program.

Program:

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

Output:

Result:
Hence, we have successfully generated the translation for the
given object using C programming language.
3D-TRANSFORMATION [SCALING]

Aim:
To perform scaling in 3D transformation using c language.

Algorithm:
1] Initialize the graphics mode.
2] Construct a 3D object.
3] Scaling
a) Get the scaling value x,y,z.
b) midx=maxx/2; midy=maxy/2
c) bar3d(midx+50,midy-100,midx+60,midy-90,5,1)
bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1)
4] Execute the program.

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 x,y,z,o,x1,x2,y1,y2;
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
printf("Enter scaling factors");
scanf("%d%d%d", &x,&y,&z);
printf("After scaling");
bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1);
getch();
closegraph();
}

Output:

Result:
Hence, we have successfully generated the scaling for the
given object using C programming language.
3D-TRANSFORMATION [ROTATION]

Aim:
To perform rotation in 3D transformation using c language.

Algorithm:
1] Initialize the graphics mode.
2] Construct a 3D object.
3] Rotation
a) Get the rotation value o.
b) About Z axis
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1)
About X axis
bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1)
About Y axis
bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1)
4] Execute the program.

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 x,y,z,o,x1,x2,y1,y2;
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
printf("Enter rotating angle");
scanf("%d",&o);
x1=50*cos(o*3.14/180)-100*sin(o*3.14/180);
y1=50*sin(o*3.14/180)+100*cos(o*3.14/180);
x2=60*cos(o*3.14/180)-90*sin(o*3.14/180);
y2=60*sin(o*3.14/180)+90*cos(o*3.14/180);
axis();
printf("After rotation about z axis");
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1);
axis();
printf("After rotation about x axis");
bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1);
axis();
printf("After rotation about yaxis");
bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1);
getch();
closegraph();
}

Output:
Result:
Hence, we have successfully generated the rotation for the
given object using C programming language.

You might also like