In our GIS development, in order to better display and display spatial data, we often need to draw symbols. circles are often used as positioning classification symbols on maps, the center of the circle is located at the center of the element. The area of the circle indicates the corresponding number of indicators.
In a computer, the circle is approaching by a polygon. When the number of sides of a polygon reaches the ground that cannot be distinguished by the human eye, it is displayed as a circle. However, if there are too many variables, the rendering effect may be affected. If the number of edges is too small, it is not like a circle. Therefore, the general practice is to consider whether a triangle composed of three adjacent points on a polygon looks like a straight line.
The specific derivation process is as follows:
Set the circle radius to R.
I drew it in the GDI environment,CodeAs follows:
Void cgeosymbol: drawcycle (CDC * PDC, int x0, int y0, double radis, double ang1, double ang2) {// convert the initial angle and end angle to the unit of radian; double AG1 = 0.01745 * ang1; double ag2 = 0.01745 * ang2; // calculate the number of edges and the angle increment value of the polygon that approaches the circle int n = (INT) (FABS (ag2-ag1)/ACOs (1-0.015/radis) + 1; double da = FABS (ag2-ag1)/n; // start to cyclically calculate the coordinates of each vertex int I = 0; while (I <= N) {double W = AG1 + I * Da; Double X = x0 + radis * Cos (w); Double Y = y0 + radis * sin (w ); if (I <= 0) {PDC-> moveTo (x, y);} else {PDC-> lineto (x, y) ;} I ++ ;}}
However, there is also a problem with the rendering effect, that is, the symbolic accuracy is not high, because the drawing functions of GDI only support integer coordinate values. When the floating coordinate is input, it is also first converted to integer coordinates and then drawn, so you can consider using a drawing interface such as GDI + or dx, OpenGL.