How to draw a polyhedron and dedocahedron in turbo c ?
any one has any idea?
Printable View
How to draw a polyhedron and dedocahedron in turbo c ?
any one has any idea?
Sure.
void DrawPolyhedron() and DrawDedocahedron() should do the trick. Do your own homework. Post questions to specific problems you're having with *your* code.
Just abstract the problem. You need to draw lines. So write a function:
void DrawLine(int start_x, int start_y, int end_x, int end_y);
You'll need a function that translates lengths and angles into variables you can pass into the drawing function.
void CalcLine(double theta, int length, int * start_x, int * start_y, int * end_x, int * end_y);
...etc, etc.
Break it up into smaller pieces, make them work, and then reassemble. Presto.
This does not show how to draw a line nor does it show how to create the figure. I leave that as an exercise for you to figure out.Code:
struct ipoint2D
{
int x;
int y;
};
void Draw(ipoint2D *points, int numpoints)
{
for (int i=0;i<numpoints;i++)
{
int x1=points[i].x;
int y1=points[i].y;
int x2=points[i+1].x;
int y2=points[i+1].y;
DrawLine (x1,y1,x2,y2);
}
int x1=points[0].x;
int y1=points[0].y;
int x2=points[numpoints].x;
int y2=points[numpoints].y;
DrawLine(x1,y1,x2,y2);
}
One hint though - if you want 20 sides to the figure you would divide 360 by 20 and increment the angle by that much each time you draw a 'side'