夏天/isummer

Sun of my life !Talk is cheap, Show me the code! 追风赶月莫停留,平芜尽处是春山~

博客园 首页 新随笔 联系 管理

中点算法绘制椭圆_程序

1. 中点算法绘制椭圆

  由于算法特殊性,程序限制绘制第一象限部分;

 1 void CCGProjectWorkView::midPoint_1P4Ellipse(int radiumA, int radiumB, const float lineColor[])
 2 {
 3     int pointX, pointY;
 4     float jugeFactorUp, jugeFactorDown;
 5     pointX = 0;
 6     pointY = radiumB;
 7 
 8     glColor3f(lineColor[0], lineColor[1], lineColor[2]);
 9     glBegin(GL_POINTS);
10 
11     jugeFactorUp = radiumB*radiumB + radiumA*radiumA*(-radiumB + 0.25);
12     glVertex3f(pointX, pointY, 0);
13     while (radiumB*radiumB*(pointX+1) < radiumA*radiumA*(pointY-0.5))
14     {
15         if (jugeFactorUp < 0)//中点在内部,正右方点H
16         {
17             jugeFactorUp += radiumB*radiumB*(2*pointX + 3);
18             pointX++;
19         }
20         else
21         {
22             jugeFactorUp += (radiumB*radiumB*(2*pointX + 3) + radiumA*radiumA*(-2*pointY + 2));
23             pointY--;
24             pointX++;
25         }
26         glVertex3f(pointX, pointY, 0);
27     }
28     
29     jugeFactorDown = sqrt(radiumB*(pointX + 0.5)) + radiumA*(pointY - 1) - radiumA*radiumB;
30     while(pointY > 0)
31     {
32         if (jugeFactorDown < 0)//在圆内,取D
33         {
34             jugeFactorDown += radiumB*radiumB*(2*pointX + 2) + radiumA*radiumA*(-2*pointY + 3);
35             pointX++;
36             pointY--;
37         }
38         else
39         {
40             jugeFactorDown += radiumA*radiumA*(-2*pointY +3);
41             pointY--;
42         }
43         glVertex3f(pointX, pointY, 0);
44     }
45     
46     glEnd();
47 
48 }

 

posted on 2015-12-14 22:02  夏天/isummer  阅读(1020)  评论(0编辑  收藏  举报