0
$\begingroup$

Assuming I have a list of nodes that have position x,y, each node has an index, and each node stores all its connections, how could I find the nearest point on a line segment? I was able to come up with something but it isn't able to differentiate between line segments and two nodes that aren't connected.

Example Picture

For example, assume I have node 1, 2, and 3. Node 1 is connected to node 2 and node 2 is connected to node 3. I have point A that I want to find the nearest point on line segments. In this case, it is some point between node 1 and 2. How could I find that point? How could I make sure that it doesn't try to check between 1 and 3?

  • 0
    What do you mean 'connected'? How do connections and indices relate to the problem?2017-02-19
  • 0
    Not every node is connected to every other node. I have a data set of nodes with their connections. I was just trying to explain the problem exactly as it is. Think about it as having a map of line segments. What is the closest point of all those line segments?2017-02-19
  • 0
    Still not clear to me. Are the connections between nodes straight line segments and is the problem then to find the nearest point on one of those line segments to a node that is not connected?2017-02-19
  • 0
    There is generally no such point. Would you perhaps be interested in finding a point that minimizes the sum of distances to each line?2017-02-19
  • 0
    I am trying to find the closest point on a line segment in a map. I am not trying to minimize distances. I added an example in my question.2017-02-19
  • 0
    In general, is point $A$ given? If so, this problem can be solved by 'checking' a finite amount of distances. The minimum distance from a point $A$ to a line $BC$ segment is always the length of $AX$, where $X$ is a point in $BC$ such that $AX\perp BC$. If no such $X$ exists, then the minimum distance will be the length of one of $AB$ or $AC$.2017-02-19

0 Answers 0