**Aim**

To Draw and visualize 3D projection Fron view top view and side view using c program 3 Dimensional Projection in C program CS1355-Graphics & Multimedia Lab projections of 3D images.

**Algorithm**

Start the program 3D projection Images

Using for loop get the no of corrdiante of the 3D view

Using line funtion in graphics we draw the projection

Front view is draw by the following code

if(i!=fs-1)

**line(x[i]+some constang value,y[i],x[i+1]+some constant value,y[i+1]);**

else

**line(x[i]+some constant value,y[i],x[0]+some constant value,y[0]);**

in For loop

like that the other top view and side view is drawn by the line function

Finally terminate the 3 Dimensional image view in Front view,Top view and side view

**Source code in C program for three dimensional Projection visualize projections of 3D images**

#include <stdio.h>

#include <stdlib.h>

#include<graphics.h>

#include<conio.h>

void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d);

void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d)

{

int i,j,k=0;

for(j=0;j<2;j++)

{

for(i=0;i<fs;i++)

{

if(i!=fs-1)

line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k);

else

line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k);

}

k=d;

}

for(i=0;i<fs;i++)

{

line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d);

}

}

void main()

{

int gd=DETECT,gm;

int x[20],y[20],tx=0,ty=0,i,fs,d;

initgraph(&gd,&gm,"");

printf("No of sides (front view only) : ");

scanf("%d",&fs);

printf("Co-ordinates : ");

for(i=0;i<fs;i++)

{

printf("(x%d,y%d)",i,i);

scanf("%d%d",&x[i],&y[i]);

}

printf("Depth :");

scanf("%d",&d);

draw3d(fs,x,y,tx,ty,d);

getch();//front view

setcolor(14);

for(i=0;i<fs;i++)

{

if(i!=fs-1)

line(x[i]+200,y[i],x[i+1]+200,y[i+1]);

else

line(x[i]+200,y[i],x[0]+200,y[0]);

}

getch();//top view

for(i=0;i<fs-1;i++)

{

line(x[i],300,x[i+1],300);

line(x[i],300+d*2,x[i+1],300+d*2);

line(x[i],300,x[i],300+d*2);

line(x[i+1],300,x[i+1],300+d*2);

}

getch();//side view

for(i=0;i<fs-1;i++)

{

line(10,y[i],10,y[i+1]);

line(10+d*2,y[i],10+d*2,y[i+1]);

line(10,y[i],10+d*2,y[i]);

line(10,y[i+1],10+d*2,y[i+1]);

}

getch();

closegraph();

}

**Output three dimensional proection front view top view side view in c program**

## No comments:

Write comments