Set Pentagram 5 vertices are abcde, vertex to axis origin distance is R,ABCDE each point with R, respectively,
A (0,R);
B (-r*sin (2/5*PI), R*cos (2/5*PI));
C (-r*sin (PI/5),-r*cos (PI/5));
De and CB about y axisymmetric.
After determining the coordinates of the 5 vertices, the Gl_line_loop function is used to connect 5 points, sequentially acebd.
The main code is:
1 void Star(void)
2 {
3
4 GLfloat r = 0.8f;
5 GLfloat PointA[2] = { 0, r };
6 GLfloat PointB[2] = { -r*sin(0.4*Pi), r*cos(0.4*Pi) };
7 GLfloat PointC[2] = { -r*sin(Pi / 5), -r*cos(Pi / 5) };
8 GLfloat PointD[2] = { r*sin(Pi / 5), -r*cos(Pi / 5) };
9 GLfloat PointE[2] = { r*sin(0.4*Pi), r*cos(0.4*Pi) };
10
11 glClear(GL_COLOR_BUFFER_BIT);
12
13 glBegin(GL_LINE_LOOP);
14 glVertex2fv(PointA);
15 glVertex2fv(PointC);
16 glVertex2fv(PointE);
17 glVertex2fv(PointB);
18 glVertex2fv(PointD);
19
20 glEnd();
21
22 glFinish();
23 }
The results of the drawing are as follows:
OpenGL Draw Pentagram