Current location - Education and Training Encyclopedia - Graduation thesis - How to draw the bottom shape recursively in C language only needs to provide ideas, without specific code! thank you
How to draw the bottom shape recursively in C language only needs to provide ideas, without specific code! thank you
Drawing a straight line requires a library function. Let's talk about ideas.

Define the type of point as having two-dimensional coordinates, such as struct point {double x;; Double y; } and so on.

The type of polygon is defined as a linear table whose elements are points, such as the linked list StructPolygon {StructPoint * p; Structure polygon * next},

You need to be able to access each point in sequence, and you need to provide an insertion function to perform the insertion point operation.

Starting from an equilateral triangle, a polygon contains three initial points which form an equilateral triangle.

The following ideas are pseudocode.

P = starting head; ;

Do {

1. each point p and the next point p->; Then, an edge of a polygon is formed, and the length of the edge is calculated;

2. Find two bisectors q 1 and q2 (the method of finding the distance of the line segment formed by two points and further finding the bisector is written as a function, not to mention the formula);

3. insert q 1 and q2 into p and p->; Between the next;

4. Take q 1 and q2 as vertices, and find the third vertex R of the triangle that grows outward (it is complicated to find the coordinates of R, and the formula can be used, but I think it can be simplified according to the angle between q 1q2 and X axis in six cases);

5. Insert r between q 1 and q2;

6.p = p- > Next;

} while (p! = nods);

//Add one round for each cycle, and consider how many rounds can meet the needs. From the picture, the second number is 3 rounds.

Next, P draws lines through each point of the polygon in turn (p, p->; Next)

Drawline(p, head) between the last point and the starting point closes the graph.

Over.