Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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

From: Edwin

Date: 8 Jul, 2010 15:05:05

Message: 1 of 5

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.


Thanks in advance

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

From: Jan Simon

Date: 8 Jul, 2010 15:43:05

Message: 2 of 5

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

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

From: Roger Stafford

Date: 8 Jul, 2010 22:04:04

Message: 3 of 5

"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.
>
> Thanks in advance
- - - - - - - - -
  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

Subject: how to determine if the shortest distance from one point to a

From: Torsten Hennig

Date: 9 Jul, 2010 11:13:39

Message: 4 of 5

> 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.
>
>
> Thanks in advance

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.

Subject: how to determine if the shortest distance from one point to a

From: Roger Stafford

Date: 9 Jul, 2010 17:25:07

Message: 5 of 5

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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us