How to compute distance of points to a line?

Click For Summary

Discussion Overview

The discussion revolves around computing the distance from multiple points to a line defined by two points in a 2D space. Participants explore the mathematical formulation and coding implementation of this concept, focusing on the shortest distance from points to the line.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant describes their approach to defining a line using vector subtraction of coordinates.
  • Another participant questions whether the problem is a homework assignment, which is clarified as a self-project.
  • A participant emphasizes the need for the shortest distance from points to the line, noting that this distance is along a line perpendicular to the original line.
  • A follow-up participant seeks confirmation on using a specific formula from a Wikipedia link for calculating the distance from a point to a line.
  • A later reply indicates that the formula was successfully implemented in Python, suggesting a resolution to the problem.

Areas of Agreement / Disagreement

Participants generally agree on the need to compute the shortest distance from points to the line and the method of using perpendicular lines for this calculation. However, there is no explicit consensus on the best approach or formula to use until the final implementation is mentioned.

Contextual Notes

The discussion does not clarify the assumptions behind the distance formula used or the specific conditions under which it applies. There may be unresolved mathematical steps in the implementation process.

Who May Find This Useful

Individuals interested in computational geometry, programming in Python, or those working on similar self-directed projects involving distance calculations in 2D space may find this discussion useful.

msn009
Messages
53
Reaction score
6
I have computed a line from point A to point B by just subtracting the coordinates as below:

line = np.array (x2-x1, y2-y1)

I am not sure if I need to form the formula for this line first by computing the slope and intercept but I continued my code as below, slope being m and b being the intercept from the formula y=mx+b

slope = (y2-y1)/(x2-x1)
b = (y2-y1) - (x2-x1)*slope

Now I am not sure how I can calculate the distance of several x,y points to this line.

can anyone help? thanks.
 
Technology news on Phys.org
Is this a homework problem?
 
no this is a self project
 
OK. When you say "the distance of several x,y points to this line" I assume you mean the standard "shortest distance", not just any old distance. If that's the case then it should be clear that the distance from any point to any line L is going to be on a line that is perpendicular to L, yes?
 
yes.. but just to be sure we are on the same page... say I have line L that I have computed as above. and I have x,y coordinates around this line or as you said that are perpendicular to this line and I now want to compute the distance of each x,y points to this line and take the point that has the maximum distance. I have attached the image for clarity. thanks
 

Attachments

  • P_20180910_140818.jpg
    P_20180910_140818.jpg
    27.1 KB · Views: 455
i tried this formula and implemented it in python, and it seems to work so this problem is solved.
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
6K
Replies
7
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
11
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K