【发布时间】:2013-01-28 01:30:21
【问题描述】:
有没有更好更快的方法来填充圆弧? 我传递给中心、半径、最小和最大角度(弧角)的函数坐标。 目前,我返回圆 (x,y,r) 内的所有像素,并检查角度之间的点角度是否插入结果中。 //lineTo (bresenham) 是返回两个像素之间的点的函数
float calculateAngle(float x0, floaty0, float x1, float y1);// returns angle between two points and x axis
std::set< std::pair<int,int> > Board::getFilledCellsinRadius(const int x,const int y,const int r, float alpha1, float alpha2)
{
std::set< std::pair<int,int> > result;
int x1;
int x2;
int counter=(y+r);
for(int count=(y-r);count<=counter;count++)
{
x1=int(x+sqrt(static_cast<double>((r*r)-((count-y)*(count-y)))+0.5));
x2=int(x-sqrt(static_cast<double>((r*r)-((count-y)*(count-y)))+0.5));
std::set< std::pair<int,int> > temp=lineTo(x1,count,x2,count);
for(std::set< std::pair<int,int> >::iterator iter=temp->begin();iter!=temp->end();++iter){
float a=calculateAngle(x,y,(*iter).first, (*iter).second);
if(a>=alpha1 && a<=alpha2){
result.insert(*iter);
}
}
}
return result;
}
【问题讨论】:
-
填充弧是指弧的整个区域?还是只画弧线?
-
等待您的函数是否返回弧内的所有点,以便您可以填充这些点?
-
@user814628 是的,弧内的所有点
-
您一定需要所有积分吗?只要有圆弧的轮廓,就可以使用填充算法绘制填充圆弧。