Showing posts with label VISUALIZING PROJECTIONS OF 3D IMAGES. Show all posts
Showing posts with label VISUALIZING PROJECTIONS OF 3D IMAGES. Show all posts

VISUALIZING PROJECTIONS OF 3D IMAGES

VISUALIZING PROJECTIONS OF 3D IMAGES

Aim :
To write a C program for implementation of Visualizing Projections Of 3d Images.

Algorithm:
Step 1: Start the program.
Step 2: input the number of edges.
Step 3: input the start pt. and end pt. for the all the edges.
Step 4: draw and display the image obtained from the these points.
Step 5: generate the top view and display it.
Step 6: generate the side view and display it.
Step 7: generate the front view and display it.
Step 8: Stop the program.

PROGRAM :

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
struct point
{
 int x,y,z;
};
struct edge
{
 struct point start;
 struct point end;
};
float pi=3.14/180.0;
void convert2d(int *x,int *y,int *z)
{
 int xp,yp;
 xp=(*x)+(*z)*cos(pi*45)/tan(pi*45);
 yp=(*y)+(*z)*sin(pi*45)/tan(pi*45);
 *x=xp;
 *y=yp;
}

void screen(int *x,int *y)
{
 int xm,ym;
 xm=getmaxx();
 ym=getmaxy();
 *x=xm/2+*x;
 *y=ym/2-*y;
}
void draw3d(struct edge po[],int n)
{
 int i,x1,y1,z1,x2,y2,z2;
 for(i=0;i<n;i++)
 {
 x1=po[i].start.x;
 y1=po[i].start.y;
 z1=po[i].start.z;
 convert2d(&x1,&y1,&z1);
 x2=po[i].end.x;
 y2=po[i].end.y;
 z2=po[i].end.z;
 convert2d(&x2,&y2,&z2);
 screen(&x1,&y1);
 screen(&x2,&y2);
 line(x1,y1,x2,y2);
 }

}
void main()
{
 int gd=DETECT,gm=0;
 int i,tx,ty,tz,sx,sy,sz,n;
 int xx1,xx2,yy1,yy2;
 float rx,ry,rz;
 struct edge p[50],q[50],r[50],s[50],t[50],v[50];
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 cleardevice();
 printf("\nEnter the number of edges:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
 printf("\nStart pt for edge %d(x,y,z):",i+1);
 scanf("%d%d%d",&p[i].start.x,&p[i].start.y,&p[i].start.z);
 printf("\nEnd pt for edge %d(x,y,z):",i+1);
 scanf("%d%d%d",&p[i].end.x,&p[i].end.y,&p[i].end.z);
 }
 cleardevice();
 printf("\n3D VIEW");
 draw3d(p,n);
 getch();
 cleardevice();

 printf("\nTOP VIEW");
 for(i=0;i<n;i++)
 {
 xx1=p[i].start.x;
 yy1=p[i].start.z;
 xx2=p[i].end.x;
 yy2=p[i].end.z;
 screen(&xx1,&yy1);
 screen(&xx2,&yy2);
 line(xx1,yy1,xx2,yy2);
 }
 getch();
 cleardevice();
 printf("\nSIDE VIEW");
 for(i=0;i<n;i++)
 {
 xx1=p[i].start.z;
 yy1=p[i].start.y;
 xx2=p[i].end.z;
 yy2=p[i].end.y;
 screen(&xx1,&yy1);
 screen(&xx2,&yy2);
 line(xx1,yy1,xx2,yy2);
 }

 getch();
 cleardevice();
 printf("\nFRONT VIEW");
 for(i=0;i<n;i++)
 {
 xx1=p[i].start.x;
 yy1=p[i].start.y;
 xx2=p[i].end.x;
 yy2=p[i].end.y;
 screen(&xx1,&yy1);
 screen(&xx2,&yy2);
 line(xx1,yy1,xx2,yy2);
 }
 getch();
 cleardevice();
}

OUTPUT:
Start pt for edge 1 (x,y,z) : 0 0 0
End pt for edge 1 (x,y,z) : 200 0 0
Start pt for edge 2 (x,y,z) : 200 0 0
End pt for edge 2 (x,y,z) : 200 0 100
Start pt for edge 3 (x,y,z) : 200 0 100
End pt for edge 3 (x,y,z) : 0 0 100
Start pt for edge 4 (x,y,z) : 0 0 100
End pt for edge 4 (x,y,z) : 0 0 0
Start pt for edge 5 (x,y,z) : 0 100 0
End pt for edge 5 (x,y,z) : 200 100 0
Start pt for edge 6 (x,y,z) : 200 100 0
End pt for edge 6 (x,y,z) : 200 100 100
Start pt for edge 7 (x,y,z) : 200 100 100
End pt for edge 7 (x,y,z) : 0 100 100
Start pt for edge 8 (x,y,z) : 0 100 100
End pt for edge 8 (x,y,z) : 0 100 0
Start pt for edge 9 (x,y,z ) : 0 100 0
End pt for edge 9 (x,y,z) : 0 0 0
Start pt for edge 10 (x,y,z): 200 100 0
End pt for edge 10 (x,y,z) : 200 0 0
Start pt for edge 11 (x,y,z): 200 100 100
End pt for edge 11 (x,y,z) : 200 0 100

Start pt for edge 12 (x,y,z): 0 100 100
End pt for edge 12 (x,y,z) : 0 0 100