码迷,mamicode.com
首页 > 编程语言 > 详细

Breaseman算法绘制圆形|中点算法绘制圆形_程序片段

时间:2015-12-14 23:17:56      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

Breaseman算法绘制圆形|中点算法绘制圆形_程序片段

1. Breaseman算法绘制圆形程序

  由于算法的特殊性,限制绘制第一象限部分,其他部分通过旋转绘制。

 1 void CCGProjectWorkView::bresenHam_1P4Circle(int radium, const float lineColor[])
 2 {
 3     int pointX, pointY, deltD, deltHD, deltDV, direction;
 4     pointX = 0;
 5     pointY = radium;
 6     deltD = 2*(1-radium);
 7 
 8     glColor3f(lineColor[0], lineColor[1], lineColor[2]);
 9     glBegin(GL_POINTS);
10     while (pointY >= 0)
11     {
12         glVertex3f(pointX, pointY, 0);
13         if (deltD < 0)//D点在圆内
14         {
15             deltHD = 2*(deltD+pointY)-1;
16             if (deltHD <= 0)
17                 direction = 1;// H 点距离最近
18             else
19                 direction = 2;// D 点距离最近
20         }
21         else if (deltD > 0)//D点在圆外
22         {
23             deltDV = 2*(deltD -pointX)-1;
24             if(deltDV <= 0)// D点里的最贱
25                 direction = 2;
26             else
27                 direction = 3;//V点距离最近
28         }
29         else
30             direction = 2;//D在圆上
31         switch(direction)
32         {
33         case 1:
34             //H点位置
35             pointX++;
36             deltD += 2*pointX+1;
37             break;
38         case 2:
39             //D点位置
40             pointX++;
41             pointY--;
42             deltD += 2*(pointX-pointY+1);
43             break;
44         case 3:
45             //V点位置
46             pointY--;
47             deltD += (-2*pointY+1);
48             break;
49         default :
50             break;
51         }
52     }
53     glEnd();
54 
55 }

2. 中点算法绘制圆形

  由于算法的特殊性,程序限制第一象限的1/8部分。

 1 //之画出正上方位于第一象限的左边的1/8园
 2 void CCGProjectWorkView::midPoint_1P8Circle(int radium, const float lineColor[])
 3 {
 4     int pointX, pointY, r;
 5     float distJugeFactor;
 6     r = radium;
 7     int deltX, deltY;//评判因子中x与y的个分量的递推分量
 8     deltX = 3;
 9     deltY = 2 - r - r;
10     distJugeFactor = 1 - r;
11 
12     pointX = 0;
13     pointY = radium;
14     glColor3f(lineColor[0], lineColor[1], lineColor[2]);
15     glBegin(GL_POINTS);
16         glVertex3f(pointX, pointY, 0);
17         while (pointX < pointY)
18         {
19             if (distJugeFactor < 0)//中点位于圆内
20             {
21                 distJugeFactor += deltX;
22                 deltX += 2;
23                 pointX++;
24             }
25             else
26             {
27                 distJugeFactor += deltX + deltY;
28                 deltX += 2;
29                 deltY += 2;
30                 pointX++;
31                 pointY--;
32             }
33             glVertex3f(pointX, pointY, 0);
34         }
35     glEnd();
36 
37 }

 

Breaseman算法绘制圆形|中点算法绘制圆形_程序片段

标签:

原文地址:http://www.cnblogs.com/icmzn/p/5046683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!