To write a c program to implement the concept of a projection.

1. Input the number of sides of an object.

2. Get the coordinates of all the sides.

3. Enter the depth of an object.

4. Using draw3d function draws the 3d representation of an object.

5. Project 3D object in 2D space.

#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,"d:\\tc\\BGI");

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

scanf("%d",&fs);

printf("Coordinates:");

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();

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();

closegraph();

}

Example Result OUTPUT Projection

No of sides(front view only):

3

Coordinates : (x0,y0)

150

150

(x1,y1)

275

100

(x2,y2)

75

75

Depth:

10

RESULT Thus the c program to implement the concept of projection was coded and executed successfully.

**STEP BY STEP PROCEDURAL ALGORITHM**1. Input the number of sides of an object.

2. Get the coordinates of all the sides.

3. Enter the depth of an object.

4. Using draw3d function draws the 3d representation of an object.

5. Project 3D object in 2D space.

**Source code Programming Projection**#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,"d:\\tc\\BGI");

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

scanf("%d",&fs);

printf("Coordinates:");

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();

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();

closegraph();

}

Example Result OUTPUT Projection

No of sides(front view only):

3

Coordinates : (x0,y0)

150

150

(x1,y1)

275

100

(x2,y2)

75

75

Depth:

10

RESULT Thus the c program to implement the concept of projection was coded and executed successfully.

## No comments:

Write comments