画圆和椭圆算法
- 中点画圆法
void MidPointCircle(int r){
int x,y,d,deltaX,deltaY;
x = 0;
y = r;
d = 1-r;
deltaX = 3;
deltaY = -2*r + 2;
while(x<=y){
if(d<0){
d+=deltaX;
deltaX+=2;
x++;
}
else{
d+=(deltaX+deltaY);
deltaX+=2;
deltaY+=2;
x++;
y--;
}
DrawPixel(x,y);
DrawPixel(y,x);
DrawPixel(-x,y);
DrawPixel(y,-x);
DrawPixel(-x,-y);
DrawPixel(-y,-x);
DrawPixel(x,-y);
DrawPixel(-y,x);
}
}
- Bersenham画圆法(优化版)
void BersenhamCircle(int r){
int x,y,delta,delta1,delta2,direction;
x=0;
y=r;
delta = 2*(1-r);
while(y>=0){
DrawPixel(x,y);
DrawPixel(-x,y);
DrawPixel(-x,-y);
DrawPixel(x,-y);
if(delta<0){
delta1 = 2*delta+2*y-1;
if(delta1<=0) direction = 1;
else direction = 2;
}
else if(delta>0){
delta2 = 2*(delta-x)+1;
if(delta2<=0) direction = 2;
else direction = 3;
}
else direction = 2;
switch(direction){
case 1:
x++;
delta+=2*x+1;
break;
case 2:
x++;
y--;
delta+=2*(x-y)+2;
break;
case 3:
y--;
delta+=1-2*y;
break;
}
}
}
- 中点画椭圆法
void MidPointEllipse(int a,int b){
int x,y;
float d1,d2;
x=0;
y=b;
d1=b*b+a*a*(-b+0.25);
while(b*b*(x+1)<a*a*(y-0.5)){
DrawPixel(x,y);
DrawPixel(-x,y);
DrawPixel(-x,-y);
DrawPixel(x,-y);
if(d1<0){
d1+=b*b*(2*x+3);
x++;
}
else{
d1+=b*b*(2*x+3)+a*a*(-2*y+2);
x++;
y--;
}
}
d2=pow(b*(x+0.5),2)+pow(a*(y-1),2)-pow(a*b,2);
while(y>=0){
DrawPixel(x,y);
DrawPixel(-x,y);
DrawPixel(-x,-y);
DrawPixel(x,-y);
if(d2<0){
d2+=b*b*(2*x+2)+a*a*(-2*y+3);
x++;
y--;
}
else{
d2+=a*a*(-2*y+3);
y--;
}
}
}
最新的GTsport,支持4k,60
fps,hdr,widecolo,vr