【问题标题】:Is there better and quicker way to fill only arc of circle (in pixels)?是否有更好更快的方法来仅填充圆弧(以像素为单位)?
【发布时间】: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 是的,弧内的所有点
  • 您一定需要所有积分吗?只要有圆弧的轮廓,就可以使用填充算法绘制填充圆弧。

标签: c++ algorithm


【解决方案1】:

为什么不返回圆弧上的点,然后用lineto函数填充圆弧呢?

弧上的点应该可以用数学计算,这样可以避免不必要的计算。

或者,绘制圆弧和 2 个半径并使用Flood Fill Algorithm 填充,谢谢@user814628

【讨论】:

  • 我不确定这是否会填满每个内部,根据线路可能是内部的一些大厅,因为它是离散的
  • @PaolaJ。你有没有尝试过?当这些点远离半径时,它们之间的距离会更远,因此径向线上的所有点都比圆弧上的点更靠近彼此。因此理论上,只要覆盖弧上的所有像素,就应该覆盖弧内的所有点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2020-05-13
  • 1970-01-01
  • 2015-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多