Solved

# Position of a point with respect to a line

Posted on 2013-12-04
301 Views
Given a point (x,y)
and a line defined by (x1, y1) and (x2, y2)

what is the distance between the point and the line? and
what is the check whether the point lies within the end points?
All in terms of x's and y's for plugging in a computer program.
0
Question by:Saqib Husain, Syed
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 84

Expert Comment

ID: 39696718
What does "within the end points" mean?
Is it a region bounded by lines through (x1, y1) and (x2, y2) perpendicular to the line between (x1, y1) and (x2, y2)?
0

LVL 43

Author Comment

ID: 39696721
Yes
0

LVL 43

Author Comment

ID: 39696729
On a drawing, they are texts written next to lines at a defined distance.
0

LVL 27

Expert Comment

ID: 39696730
There is a formula for the distance from a point to a line (not a line segment).

http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

You would have to convert your line segment into the   ax + by + c = 0 form.
0

LVL 84

Accepted Solution

ozo earned 500 total points
ID: 39696743
distance = |(x1-x)(y2-y)-(x2-x)(y1-y)|/sqrt((x1-x2)^2+(y1-y2)^2)

when ((x1-x2)*(x-x2)+(y1-y2)*(y-y2))/((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) is between 0 and 1, the point is within the end points
0

LVL 43

Author Closing Comment

ID: 39697064
Great, thanks. Working perfectly.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…