Talk:Distance from a point to a line

Algebraic proof
There is a major jump in the algebraic proof when it begins with "Then it is necessary to show.."
 * I agree. I rephrased the vector version to be more detailed. I'm not going to touch the algebraic version -- it's way more complicated and has more ugly details than the vector version. I added reqdiagram because a diagram would really help the vector explanation. —Ben FrantzDale (talk) 12:32, 17 August 2011 (UTC)

Images
We would like to add images to this page, but because we are new users we are not allowed to upload files. If anyone would like to assist, we found some images at that we believe would be helpful. Thanks! Kcoccio024 (talk) 18:32, 6 December 2013 (UTC)


 * okay 41.13.72.85 (talk) 16:01, 28 August 2023 (UTC)

Sphere
Ah, but the surface of the earth is more like a sphere. Mention how to deal with that too. Jidanni (talk) 12:23, 22 December 2013 (UTC)

Possible mathematical error?
The very first section of this page, titled Cartesian Coordinates appears to be wrong. I spent a good while being confused as to why a mathematical computer program I was writing was malfunctioning, until I realized that the following equation (which I was trying to use) doesn't seem to be true at all:

$$\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}. $$

Consider the very basic line, y = x.

The standard form of this equation (ax + by + c = 0) is: -x + y = 0. This means that:

a = -1 b = 1 c = 0

These values satisfy the conditions listed on the article: "where a, b and c are real constants with a and b not both zero"

Yet clearly, the distance equation listed will always return a distance of zero for any point.

Alexanderzero (talk) 06:16, 13 January 2014 (UTC) alexanderzero
 * I don't see why you think you only get zero distances (you do if you only deal with points on the line y = x). Try the point (1,2). It's distance from y = x is 1/√2.Bill Cherowitzo (talk) 04:31, 14 January 2014 (UTC)


 * As Alexanderzero sayed, the equation is wrong. It returns only the correct distances for horizontal, vertical and diagonal (with an angle of 90°)lines. As Alexanderzero, I spend some time to figure that out. To save other people's time, I would suggest to correct it. One correct equation for calculating the distance can be found here: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.htmlJanDotNet (talk) 06:35, 8 June 2017 (UTC)


 * I am puzzled by your response. Look at equation (11) of your source. It is identical to the formula used on this page.--Bill Cherowitzo (talk) 15:29, 8 June 2017 (UTC)

Section "Vector formulation" is also wrong
My computations show that the formula in Section "Vector formulation" is also wrong. For a correct formula (written in details for the 3d case, but siutable for n dimensions as well), see http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html. $$d^2$$ is shown in (6). — Preceding unsigned comment added by Makrai (talk • contribs) 10:15, 13 March 2014 (UTC)
 * I would check your computations again. The formula derived in the article is a simple application of vector projection and is not in error. If you think you have a counter-example please provide the details here. (The supposed error of the previous post did not exist, so your use of "also" is not quite correct.)Bill Cherowitzo (talk) 22:54, 13 March 2014 (UTC)
 * The text of the article uses p-a. The illustration next to it uses a-p.  They can't both be correct.
 * Upon further review, it seems that this "simple application" of vectors was changed on "20:39, 20 December 2021" to flip the text (but not the illustration), as it had apparently been backwards since this article was created in 2009.
 * Do we now think the text is now correct, and only the illustration needs fixing? 2601:602:A080:1240:4C57:655D:1A04:F659 (talk) 04:02, 9 October 2023 (UTC)

Geometric proof???
The statements under the heading of Proof 2 (geometric proof) do not form a proof (the unjustified statement about the ratio of the sides of the right triangle requires a proof and has exceptions if either a or b is 0). Nor is this argument particularly geometric - the coordinate computations are just not presented. I consider this section just a piece of incorrect OR and propose that we get rid of it and replace it with a proof based on geometric transformations (say a well chosen rotation about the given point). Unfortunately I don't have a ready reference for such a proof, does anyone know of one? Bill Cherowitzo (talk) 05:05, 15 January 2014 (UTC)

I found a correct geometric proof (using similar triangles) and have replaced the suspect one. I still think that a transformation proof would be a nice addition. Bill Cherowitzo (talk) 22:59, 20 January 2014 (UTC)

Last section
The recent edit that placed the two point version of the formula into the Cartesian coordinate section, while not a bad edit, has created a problem with the last section of this article. That section is devoted to this version of the formula and so is now redundant. There is some additional material in this section and my question is – is any of it worth saving? Bill Cherowitzo (talk) 19:13, 7 December 2014 (UTC)
 * I've deleted the now-redundant section, preserving the additional material which I've put into the Cartesian coordinate section. I've done a bot of fiddling to make it all a coherent whole. I hope this works for everyone. DOwenWilliams (talk) 22:53, 8 December 2014 (UTC)

Even easier way for Vector formulation, incl. signed distance
It's trivial to create a Vector orthogonal to n (which, as n is supposed to be a unit vector, is one as well): $$o = (n.y, -n.x)$$

It's n rotated 90° clockwise.

Now one can just project the vector between a and p onto this orthogonal vector: $$ signedDistance(x = a + tn, p) = (p-a)*o $$

It will be a positive value if it's on the right side of the line (relative to n), negative if it's on the left side.

If you only want the distance without a sign, just its absolute value. — Preceding unsigned comment added by 31.18.153.90 (talk) 01:55, 15 February 2015 (UTC)


 * The problem is that your 'trivial' first step is restricted to two dimensions; it does not work in higher dimensions. Given that, you've not really got a vector method but a 2D coordinate method, which must get the same answer as the earlier 2D formula.-- JohnBlackburne wordsdeeds 02:28, 15 February 2015 (UTC)


 * The current formula assumes a "1x2 vector", which is 2D as well. But it mentions it also works for more than two dimensions so yeah, this simple way wouldn't work there. And, thinking about it, it only works for cartesian coordinate systems. Still, it's a nice and simple way for a signed distance in the common cartesian 2D case. — Preceding unsigned comment added by 31.18.153.90 (talk) 02:44, 15 February 2015 (UTC)

Nomenclature in "Vector formulation"
The nomenclature in the "Vector formulation" section is inconsistent/ambiguous. The same labels are being used for points and vectors, which will confuse readers. For example, vector p might describe the location of point P with respect to the origin. (Incidentally, I prefer to stick to the NIST/IUPAC/ISO standard to set all variables in italic, including vectors.) —DIV (120.19.123.255 (talk) 13:52, 30 August 2016 (UTC))

Improper use of the word "distance"
From the geometrical point of view it makes no sense to say "shortest distance" because by definition there is only one distance. If it's not "the shortest", it's not a distance. It would be better to say: "the shortest length among the length of the segments from the point and any point of the line". OK, I wrote it in a very long way, it could be shorter with somenthing implied. --Angelo Mascaro (talk) 15:22, 30 November 2016 (UTC)
 * While you are making a valid point, you are fighting an uphill battle. The English language does not always provide the exactness that a mathematician requires. In this case, the phrase "the shortest distance from a point to a line", has always stood as an abbreviation of – the shortest, among all the distances from a fixed point to any point on a line. Distance, in its most basic form, is defined between points. Using this basis the concept of distance can then be extended, as it is here, to distances between points and sets of points. Although the word is the same, this is a higher order concept of distance. The lead sentence (before I changed it) was not a definition as it simply repeated the phrase. What my edit did was to turn the lead into a definition by defining the concept in terms of the more primitive distance between points. This could all be done in terms of lengths of line segments as you have suggested, but I am not sure that that approach is clearer.--Bill Cherowitzo (talk) 19:11, 30 November 2016 (UTC)

Misleading title
The title of this article is misleading. It implies that it contains algorithms and information on finding the minimum distance from a point to a finite line, when in reality it is the distance from a point to an infinite line. I tried editing one of the section headings, but it appears to have been reverted.

To that end, I propose that this page be moved to more appropriately reflect it's content.--5.198.44.45 (talk) 21:56, 23 November 2017 (UTC)
 * As Wcherowi explained when he reverted your edits, all lines are infinite. A line segment is finite.  The article's title is correct and no movement is required. Martin of Sheffield (talk) 22:19, 23 November 2017 (UTC)
 * That depends on your perspective. While I have no doubt that a Mathematician would know precisely what is meant by the title here, a computer scientist who's not got a strong background in maths (such as myself) may read an understand it incorrectly - as proof, I ended up implementing it in JS and pulling it apart and putting it together again multiple times before I realised that it was for an infinite line and not a finite one. Perhaps a single sentence could be added then? Surely it doesn't hurt to aid clarity? --5.198.44.45 (talk) 11:48, 29 November 2017 (UTC)
 * Well, speaking as someone who didn't study maths beyond 18 and who has spent the last 35 years in the computer industry, it seemed clear enough to me. ;-) I've added the word "infinite" though to address your concerns.

"Line defined by two points" sections + simpler formula with vector derivation
The article seems to be lacking discussion regarding a line defined by two points, which is more practical for programmers. The existing formula can also be expressed in a neater form (verified using Mathematica, but source is still required), which may be more practical in programs. The wiki page linked in the section Line defined by two points, Area of a triangle § Using coordinates, requires relatively advanced mathematical knowledge.

I propose a simpler vector derivation below for the distance between a point and a line defined by two points, however I need to find a source that has it. It begins similarly to the existing section—A vector projection proof—then proceeds to obtain convenient values for a and b. The equation for the line $$ax + by + c = 0$$ should be omitted from the explanation to distinguish it from the sections involving the equation of the line.

I also propose dividing the proofs section into proofs/derivations concerning a line defined by an equation and a line defined by two points, and to move the existing explanation of the derivation in Line defined by two points into that section. This would separate the proof/derivation explanations from the formulas for the distance, and mirror the subsections of the Cartesian Coordinates section in the proofs section.

New vector derivation for the distance between a point and a line defined by two points
After obtaining
 * $$ d = \frac{|a(x_0 - x_1) + b(y_0 - y_1)|}{\sqrt{a^2 + b^2}}.$$

through the same method as the linked section, we attempt to to find the values for $$a$$ and $$b$$. Let $$C(x_2, y_2)$$ be the second point on the line.

Since $$\mathbf{n}$$ is perpendicular to $$\overrightarrow{QC}$$, the dot product rule states that $$\overrightarrow{QP} \cdot \mathbf{n} = 0$$. If we let $$A = \overrightarrow{QC_x}$$ and $$B = \overrightarrow{QC_y}$$, expanding this equation gives $$A \cdot a + B \cdot b = 0$$. Combining this equation with $$\| \mathbf{n}\| = \sqrt{a^2 + b^2}$$ and solving for $$a^2$$ and $$b^2$$ gives
 * $$a^2 = \frac{\| \mathbf{n}\|^2 B^2}{A^2 + B^2}$$
 * $$b^2 = \frac{\| \mathbf{n}\|^2 A^2}{A^2 + B^2}$$

For convenience, let $$\| \mathbf{n}\| = 1$$. Since $$A \cdot a + B \cdot b = 0$$, either
 * $$a > 0$$ and $$ b < 0$$

or
 * $$a < 0$$ and $$b > 0$$.

Choosing the formal, we obtain
 * $$ d = \frac{|B(x_0 - x_1) - A(y_0 - y_1)|}{\sqrt{A^2 + B^2}}.$$

which leads to a neater equation than the existing one:
 * $$ d = \frac{|(x_0 - x_1)(y_2 - y_1) - (y_0 - y_1)(x_2 - x_1)|}{\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}}.$$

Aaronshenhao (talk) 03:00, 8 June 2019 (UTC)

Article title is misleading
The subject of this article is NOT the Distance from a point to a line. The subject is the Distance from a point to a line in two (Cartesian) dimensions. Real world cases often involve the two dimensions on the surface of a sphere (i.e Earth (idealized)) or 3 dimensions, as well as the distances in a flat 2d surface. Surely both of these other cases are encountered often enough -outside of, what? 7th Grade math class?- to merit at least a mention - as well as a link. I think they both deserve their own complete sections. And. Shouldn't some mention be made of other types (non-Euclidean) of metric spaces as well as (maybe) non-metric spaces?40.142.185.108 (talk) 12:24, 22 August 2019 (UTC)


 * Please feel free to add information on the more general formulae. Find a good maths book and from it develop your text. Martin of Sheffield (talk) 21:41, 24 August 2019 (UTC)

Please explain the variables better.
Please explain what the values: a, b & c is.

All I can read is that it is "where a, b and c are real constants with a and b not both zero".

But that explains NOTHING about HOW I should get a, b or c, nor what they symbolizes, or what function they have in the formula.

You shouldn't have to be a math professor to understand this, at least add a picture or something that explains what parts they come from in that example.

Thanks.

--178.251.245.195 (talk) 17:53, 22 December 2019 (UTC)

'Illustration of vector formulation" incorrect differences in the figure
The figure has (a-p) noted beside different vectors. They should be (p-a) as used in the body of the Vector Formulation section.

I find the figure very helpful, just needs those (a-p)'s to be (p-a)'s. I'm unfamiliar with how to update wikipedia. I'll read up on that. Jvskinner (talk) 03:32, 18 February 2024 (UTC)