How to compute distance of points to a line?

In summary, the conversation discusses computing a line from point A to point B by subtracting coordinates, calculating the slope and intercept, and finding the distance of several x,y points to this line. The formula for calculating the distance from a point to a line is used to solve the problem.
  • #1
msn009
53
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
  • #2
Is this a homework problem?
 
  • #3
no this is a self project
 
  • #4
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?
 
  • #5
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: 398
  • #7
i tried this formula and implemented it in python, and it seems to work so this problem is solved.
 

FAQ: How to compute distance of points to a line?

How do I find the equation of a line?

To find the equation of a line, you will need two points on the line. Then, you can use the formula y = mx + b, where m is the slope of the line and b is the y-intercept. You can find the slope by using the formula (y2-y1)/(x2-x1), where (x1,y1) and (x2,y2) are the coordinates of the two points. Once you have the slope and the y-intercept, you can plug them into the equation and simplify to get the final equation of the line.

What is the distance formula for finding the distance between a point and a line?

The distance formula for finding the distance between a point and a line is d = |Ax + By + C| / √(A^2 + B^2), where (x,y) is the coordinates of the point and A, B, and C are the coefficients of the line's equation (Ax + By + C = 0). This formula is derived from the perpendicular distance between a point and a line.

Can I use the Pythagorean Theorem to find the distance between a point and a line?

Yes, you can use the Pythagorean Theorem to find the distance between a point and a line. First, you will need to find the shortest distance between the point and the line (which is the perpendicular distance) using the distance formula mentioned above. Then, you can use the Pythagorean Theorem (a^2 + b^2 = c^2) to find the hypotenuse, which is the distance between the point and the line.

How do I compute the distance of a point to a line in 3D space?

To compute the distance of a point to a line in 3D space, you will need to first find the equation of the plane that contains the line. Then, you can use the formula d = |Ax + By + Cz + D| / √(A^2 + B^2 + C^2), where (x,y,z) is the coordinates of the point and A, B, C, and D are the coefficients of the plane's equation (Ax + By + Cz + D = 0). This formula is derived from the perpendicular distance between a point and a plane.

Can I use the distance formula to find the distance between two lines in 3D space?

No, the distance formula mentioned above only works for finding the distance between a point and a line or a point and a plane. To find the distance between two lines in 3D space, you will need to use vector equations and the cross product. This is a more complex process that involves finding the closest points on each line and then calculating the distance between them.

Similar threads

Back
Top