nearest Manhattan distance between a point and line

后端 未结 1 649
囚心锁ツ
囚心锁ツ 2021-01-17 01:25

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 l

相关标签:
1条回答
  • 2021-01-17 02:16

    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.

    0 讨论(0)
提交回复
热议问题