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

时间:2021-05-01 06:07:23

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

1. Breaseman算法绘制圆形程序

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

 void CCGProjectWorkView::bresenHam_1P4Circle(int radium, const float lineColor[])
{
int pointX, pointY, deltD, deltHD, deltDV, direction;
pointX = ;
pointY = radium;
deltD = *(-radium); glColor3f(lineColor[], lineColor[], lineColor[]);
glBegin(GL_POINTS);
while (pointY >= )
{
glVertex3f(pointX, pointY, );
if (deltD < )//D点在圆内
{
deltHD = *(deltD+pointY)-;
if (deltHD <= )
direction = ;// H 点距离最近
else
direction = ;// D 点距离最近
}
else if (deltD > )//D点在圆外
{
deltDV = *(deltD -pointX)-;
if(deltDV <= )// D点里的最贱
direction = ;
else
direction = ;//V点距离最近
}
else
direction = ;//D在圆上
switch(direction)
{
case :
//H点位置
pointX++;
deltD += *pointX+;
break;
case :
//D点位置
pointX++;
pointY--;
deltD += *(pointX-pointY+);
break;
case :
//V点位置
pointY--;
deltD += (-*pointY+);
break;
default :
break;
}
}
glEnd(); }

2. 中点算法绘制圆形

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

 //之画出正上方位于第一象限的左边的1/8园
void CCGProjectWorkView::midPoint_1P8Circle(int radium, const float lineColor[])
{
int pointX, pointY, r;
float distJugeFactor;
r = radium;
int deltX, deltY;//评判因子中x与y的个分量的递推分量
deltX = ;
deltY = - r - r;
distJugeFactor = - r; pointX = ;
pointY = radium;
glColor3f(lineColor[], lineColor[], lineColor[]);
glBegin(GL_POINTS);
glVertex3f(pointX, pointY, );
while (pointX < pointY)
{
if (distJugeFactor < )//中点位于圆内
{
distJugeFactor += deltX;
deltX += ;
pointX++;
}
else
{
distJugeFactor += deltX + deltY;
deltX += ;
deltY += ;
pointX++;
pointY--;
}
glVertex3f(pointX, pointY, );
}
glEnd(); }