资源简介
采用完全Bresenham算法生成椭圆,有别于中点Bresenham算法生成椭圆
代码片段和文件信息
#include
#include
void drawEllipse (int a int b int xLoc int yLoc)
{
glPushMatrix ();
int x y;
float p1 p2 aa bb;
aa = a * a;
bb = b * b;
p1 = -2*b+1;
glTranslatef ((GLfloat) xLoc (GLfloat) yLoc 0.0f);
x = 0;
y = b;
glBegin (GL_POINTS);
glVertex2i ( x y);
glVertex2i (-x y);
glVertex2i (-x -y);
glVertex2i ( x -y);
while (bb*x {
if (p1 <=0)
{ p1+=(2*bb*(2*x+1))/a*a;
}
else
{ p1+=2*bb*(2*x+1)/a*a+2*(-2*y+1)+2;
-- y;
}
++ x;
glVertex2i ( x y);
glVertex2i (-x y);
glVertex2i (-x -y);
glVertex2i ( x -y);
}
p2 = 2*y*y-2*y-2*(aa*bb-bb*x*x)/aa+1;//2*x*x+2*x-2*(aa*bb-aa*(y-1)*(y-1))/bb+1;
while (y>0)
{
if (p2 <= 0)
{
++ x;
p2+=2*aa*(-2*y+1)/bb+2*(2*x+1)+2;
}
else
{
p2+=2*aa*(-2*y+1)/bb;
}
-- y;
glVertex2i ( x y);
- 上一篇:飞机订票系统,c++程序
- 下一篇:C语言写矩阵库,适合做矩阵运算
评论
共有 条评论