简体   繁体   中英

When drawing an arbitrary point in an image, how to find the coordinates of the two closest lines perpendicular to that point?

在此处输入图像描述

I draw an arbitrary point in this image.

I want to find the coordinates of the two lines closest to this point.

It should be a straight line when you connect one of the two points to any point.

Like this:

在此处输入图像描述

I want to know two thing

  • First, Is there a library to find the nearest line from an arbitrary point?

  • Second, Is there any library or algorithm to find a point perpendicular to an arbitrary point?

Please help me.....

You can do this in two steps: first for the closest line, then for the other one.

  • The closest line : Let A be the arbitrary point. You can calculate the distance of each white pixel to point A and keep the shortest distance (sqrt((xa.x)^2 + (ya.y)^2) . This closest pixel (let's call it P ) is the projected point on the line. By definition of the projected point, the line AP is perpendicular to the line.
  • The other line : color all the points of the closest line so as not to search again in its pixels, do the same thing as for the closest line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM