Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Position of a point with respect to a line

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
Saqib Husain, Syed
Asked:
Saqib Husain, Syed
  • 3
  • 2
1 Solution
 
ozoCommented:
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
 
Saqib Husain, SyedEngineerAuthor Commented:
Yes
0
 
Saqib Husain, SyedEngineerAuthor Commented:
On a drawing, they are texts written next to lines at a defined distance.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
d-glitchCommented:
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
 
ozoCommented:
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
 
Saqib Husain, SyedEngineerAuthor Commented:
Great, thanks. Working perfectly.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now