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

我想找到与指定像素(例如,绿色像素)具有最大直线距离的像素.并且连接两个像素的直线(红线)不得离开该组.
我的解决方案是循环度数并模拟从绿色像素开始的线条的进度,并查看哪条线走过最远的距离.
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)