Friday, 27 September 2013

3D TRANSFORMATION - SCALING in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year






AIM:

To implement 3D transformation of Scaling.

ALGORITHM:

1. Scaling with respect to a select fixed position (xf,yf,zf) can be represented with the following transformation sequence.

2. Translate the fixed point to the origin

3. Scale the object relative to coordinate origin using the following matrix

X’ sx 0 0 x

y’ = 0 sy 0 . y

z’ 0 0 sz z



4. Translate the fixed point back to its original position.



SOURCE CODE:

#include

#include

#include

#include

#include

void main()

{

int n,sx,sy,d,p1[10][3],p2[10][3];

int i,gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc\\bgi");

printf("\nEnter the number of lines:");

scanf("&d",&n);

printf("\nEnter the values of edges");

for(i=1;i<=n;i++)

{

scanf("%d%d",&p1[i][1],&p1[i][2]);

}

printf("\nEnter the depth:");

scanf("%d",&d);

cleardevice();

for(i=1;i<=n;i++)

{

p2[i][1]=p1[i][1]+d;

p2[i][2]=p2[i][2]+d;

}

getch();

cleardevice();

printf("\nBefore Scaling");

for(i=1;i
{

line(p1[i][1],p1[i][2],p1[i+1][1],p1[i+1][2]);

}

line(p1[1][1],p1[1][2],p1[n][1],p1[n][2]);

for(i=1;i
{

line(p2[i][1],p2[i][2],p2[i+1][1],p2[i+1][2]);

}

line(p2[1][1],p2[1][2],p2[n][1],p2[n][2]);

for(i=1;i<=n;i++)

{

line(p1[i][1],p1[i][2],p2[i][1],p2[i][2]);

}

getch();

cleardevice();

printf("\nEnter the Scaling parameters Sx,Sy:\t");

scanf("%d%d",&sx,&sy);

for(i=1;i<=n;i++)

{

p1[i][1]=p1[1][1]-(p1[1][1]-p1[i][1])*sx;

p1[i][2]=p1[1][2]-(p1[1][2]-p1[i][2])*sy;

p2[i][1]=p2[1][1]-(p2[1][1]-p2[i][1])*sx;

p2[i][2]=p2[1][2]-(p2[1][2]-p2[i][2])*sy;

}

getch();

cleardevice();

printf("\nAfter Scaling");

for(i=1;i
{

line(p1[i][1],p1[i][2],p1[i+1][1],p1[i+1][2]);

}

line(p1[1][1],p1[1][2],p1[n][1],p1[n][2]);

for(i=1;i
{

line(p2[i][1],p2[i][2],p2[i+1][1],p2[i+1][2]);

}

line(p2[1][1],p2[1][2],p2[n][1],p2[n][2]);

for(i=1;i<=n;i++)

{

line(p1[i][1],p1[i][2],p2[i][1],p2[i][2]);

}

getch();

}







OUTPUT:


Enter the no of lines: 3

Enter the values: 50 60 55 64 85 65

Enter the depth: 95



Enter the scaling factors: 25 30








No comments:

Don't You Think this Awesome Post should be shared ??
| 3D TRANSFORMATION - SCALING in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year |
Back To Top Related Posts Plugin for WordPress, Blogger...