COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### how to determine if the shortest distance from one point to a line is inside the line segment or outside

• Follow

```Hello everyone,
We know how to determine the shortest distance from a point to a line.

http://www.mathworks.com/support/solutions/en/data/1-1BYSR/index.html?product=ML&solution=1-1BYSR

However, can someone point me of a way of how to determine if such minimum
distance fall within the line segment or it is determine it with respect to its projection.

for example for the line
line=[-15	-30
-50	75
-70	95]

point=[0 0]

for the first segment of the line the shortest distance (perpendicular distance)
falls within the line segment but for the second segment the shortest distance is determine it with respect the line projection. So How could I know when each case is happening.

```
 0

```Dear Edwin,

> line=[-15	-30
> -50	75
> -70	95]

Is this a [3 x 2] matrix? How is the "line" defined by these values? 2 points or one point a orientation vector?

However, find the point, where the shortest distance between the point and the line touchs the line. Then determine, in this point is between the two points defining the line.

I do not want to solve a homework, but of course you can get comments for all what you have done so far.

Kind regards, Jan
```
 0

```"Edwin " <onest30@gmail.com> wrote in message <i14pf1\$41k\$1@fred.mathworks.com>...
> Hello everyone,
> We know how to determine the shortest distance from a point to a line.
>
> http://www.mathworks.com/support/solutions/en/data/1-1BYSR/index.html?product=ML&solution=1-1BYSR
>
> However, can someone point me of a way of how to determine if such minimum
> distance fall within the line segment or it is determine it with respect to its projection.
>
> for example for the line
> line=[-15	-30
> -50	75
> -70	95]
>
> point=[0 0]
>
> for the first segment of the line the shortest distance (perpendicular distance)
> falls within the line segment but for the second segment the shortest distance is determine it with respect the line projection. So How could I know when each case is happening.
>
- - - - - - - - -
Suppose A and B are the two endpoints of your line segment and C is the point you are asking about.  Now consider the triangle ABC.  If the perpendicular projection of C onto line AB lies within segment AB, what can you say about the two angles CAB and CBA?  You don't even have to find the point of projection of C onto AB in order to answer that easy question.  I DOT if you will have any trouble with this.  :-)

Roger Stafford
```
 0

```> Hello everyone,
> We know how to determine the shortest distance from a
> point to a line.
>
> http://www.mathworks.com/support/solutions/en/data/1-1
> BYSR/index.html?product=ML&solution=1-1BYSR
>
> However, can someone point me of a way of how to
> determine if such minimum
> distance fall within the line segment or it is
> determine it with respect to its projection.
>
> for example for the line
> line=[-15	-30
> -50	75
> -70	95]
>
> point=[0 0]
>
> for the first segment of the line the shortest
> distance (perpendicular distance)
> falls within the line segment but for the second
> segment the shortest distance is determine it with
> respect the line projection. So How could I know when
> each case is happening.
>
>

In the notation of the link above, if
v1 = (v11,v12), v2 = (v21,v22), pt = (pt1,pt2)
then the point with the smallest distance to pt on
the line through v1 and v2 lies on the line segment
(v1v2) if the quantity
lambda = ((v11-v21)*(v11-pt1)+(v12-v22)*(v12-pt2))/
((v11-v21)^2 + (v12-v22)^2)
is between 0 and 1.

Best wishes
Torsten.
```
 0

```Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <1987639511.93716.1278674049147.JavaMail.root@gallium.mathforum.org>...
> In the notation of the link above, if
> v1 = (v11,v12), v2 = (v21,v22), pt = (pt1,pt2)
> then the point with the smallest distance to pt on
> the line through v1 and v2 lies on the line segment
> (v1v2) if the quantity
> lambda = ((v11-v21)*(v11-pt1)+(v12-v22)*(v12-pt2))/
>          ((v11-v21)^2 + (v12-v22)^2)
> is between 0 and 1.
>
> Best wishes
> Torsten.
- - - - - - - -
Or equivalently, if the two angles CAB and CBA I referred to earlier are each no greater than pi/2, which can be tested by:

dot(C-A,B-A) >= 0 and dot(C-B,A-B) >= 0

Roger Stafford
```
 0

4 Replies
344 Views