小编Ray*_*eon的帖子

如何在同一像素组中找到距离另一个像素最远的像素

"组"是指一组像素,使得每个像素至少在同一组中具有一个相邻像素,该图示出了组的示例.

一个小组的例子

我想找到与指定像素(例如,绿色像素)具有最大直线距离的像素.并且连接两个像素的直线(红线)不得离开该组.

我的解决方案是循环度数并模拟从绿色像素开始的线条的进度,并查看哪条线走过最远的距离.

longestDist = 0
bestDegree = -1
farthestX = -1
farthestY = -1
FOR EACH degree from 0 to 360
    dx=longestDist * cos(degree);
    dy=longestDist * sin(degree);
    IF Point(x+dx , y+dy) does not belong to the group
        Continue with next degree
        //Because it must not be the longest line, so skip it
    END IF
    (farthestX , farthestY) = simulate(x,y,degree)
    d = findDistance(x , y , farthestX , farthestY)
    IF d > longestDist
        longestDist = d
        bestDegree = degree
    END …
Run Code Online (Sandbox Code Playgroud)

algorithm point pixel distance

6
推荐指数
1
解决办法
990
查看次数

标签 统计

algorithm ×1

distance ×1

pixel ×1

point ×1