3 DIMENSIONAL SCALING
#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 scaling();
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();
scaling();
disp2();
getch();
return;
}
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]);
return;
}
void scaling()
{
float
sx,sy,sz,i,dep;
printf("Enter
the scale factors(3 values): ");
scanf("%f%f%f",&sx,&sy,&sz);
for(i=0;i<vertices;i++)
{
tx[i]=px[i]*sx;
ty[i]=py[i]*sy;
dep=depth*sz;
tx2[i]=tx[i]+dep;
ty2[i]=ty[i]+dep;
}
}
3-DIMENSIONAL SCALING
OUTPUT:
Enter the number of vertices: 3
Enter the depth value : 15
Enter the x and y coordinates : 100
50
50
50
50
100
Enter the scale factors ( 3 values ) : 2
2
2
0 comments:
Post a Comment