0

I know that this question has been up before, but I'll give it a shot since it's not exactly the same question.

Imagine a straight line consisting of a start point and an end point. The orientation of the line in 2D can be whatever we choose. Now imagine that we are traveling along this line, but not exactly on the line. I would like to give the directional (e.g right, left) feedback so that they know what direction to head to stay on the line.

I've been reading and trying this solution: Calculate on which side of a straight line is a given point located?

I'm currently stuck when trying to grasp what happens if we travel in the opposite direction.. I's there a solution that will always give us the correct direction? No matter the line's orientation and our traveling direction. I have the possibility to place one or more reference points in the plane that are known.

Simon
  • 1
  • Is the line of finite length? – Parcly Taxel Aug 18 '16 at 07:03
  • Yes. Everything is to be done in WGS84 coordinate system. I have access to the exact location of the traveler Latitude and Longitude, the same goes for start and end coordinates of the line. I also have a bearing, although not that accurate. – Simon Aug 18 '16 at 07:07
  • Be careful with WGS84. Latitude and longitude don't have the same scale except at the equator, as I showed here. – Parcly Taxel Aug 18 '16 at 07:22
  • Thank you for noting that. The distances we are talking about are never more than 10-20 meters. And doesn't need to be more exact than +-0.5 meter. Since I'm using a GPS with an accuracy of about 1-2 meters. Does that make sense? – Simon Aug 18 '16 at 07:27

1 Answers1

0

Let the line segment be represented by the equation $\mathbf a+\lambda\mathbf b$, where $0\le\lambda\le1$; it starts at $\mathbf a$ and ends at $\mathbf a+\mathbf b$. We are at a point $\mathbf p$ not on the line, and we need to get back to the line; while there are infinitely many ways to do so I will concentrate on the manner that gives the shortest distance back.

This shortest route from $\mathbf p$ runs straight, and perpenducular to the line, meeting it at $\mathbf q$:

a---q-->a+b
    ^
    |
    |
    p

We can write an equation to express that the line and the shortest route back are perpendicular: $$(\mathbf q-\mathbf p)\cdot\mathbf b=0$$ Since $\mathbf q$ is on the line we may expand it to get $$(\mathbf a+\lambda\mathbf b-\mathbf p)\cdot\mathbf b=0$$ This is a linear equation in $\lambda$, so may be solved easily. Because the line is finite, however, there are three cases:

  • If $0\le\lambda\le1$, $\mathbf q=\mathbf a+\lambda\mathbf b$ is a point on the line segment itself. We should head towards $\mathbf q$ if we are to get back to the line in the shortest distance.
  • If $\lambda<0$, $\mathbf q$ is an imaginary point before the line's start, and we should head to the start ($\mathbf a$).
  • Similarly, if $\lambda>1$, $\mathbf q$ lies beyond the line's end, and we should head to the end ($\mathbf a+\mathbf b$).

In other words, if $\lambda$ is less than 0 then take it as 0; if it is greater than 1 then take it as 1. Then find $\mathbf q$ normally and direct yourself there.

More formally, $\mathbf q$ before the correction to $\lambda$ is the projection of $\mathbf p$ on the line segment extended infinitely in both directions.

Parcly Taxel
  • 105,904