nearest Manhattan distance between a point and line

谁说胖子不能爱 提交于 2019-12-19 11:57:09

问题


I want to find the point on a line segment drawn in an image which is at smallest Manhattan distance from a given point.

Obvious method is to get the pixels on the line segment and for each pixel calculate the distance to get the minimum. But can we do better than this ?


回答1:


This is a search problem. You need to start from your point and apply a breadth first search, grow until you hit a line pixel. The children states for any pixel should be right - up - left - down neighbors. The manhattan distance will be nothing but the depth of the goal.

EDIT: Remember to add some heuristics for faster search, for e.g. if all line pixels are to the left of the starting point; you don't need to visit right. The angle of the line would be another thing to consider, for further reduction of states.



来源:https://stackoverflow.com/questions/21704257/nearest-manhattan-distance-between-a-point-and-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!