Sunday, November 25, 2012

3 DIMENSIONAL TRANSLATION


3 DIMENSIONAL TRANSLATION

#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 translation();
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();
            translation();
            disp2();
            getch();
}
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 translation()
{
            float dx,dy,i;
            printf("Enter the translation value ( 2 values )  : ");
            scanf("%f%f",&dx,&dy);
            for(i=0;i<vertices;i++)
            {
                         tx[i]=px[i]+dx;
                         ty[i]=py[i]+dy;
                        tx2[i]=dx+px2[i];
                         ty2[i]=dy+py2[i];
            }
}


                       















3-DIMENSIONAL TRANSLATION


OUTPUT:


Enter the number of vertices: 3
Enter the depth value : 10
Enter the x and y coordinates : 100
200
200
200
200
100











0 comments:

Post a Comment