Choose how the line is written (general form or slope-intercept form), then enter the coefficients and the coordinates of the point. The equation below is linked to the input fields, so you can also edit the numbers in the equation directly.
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formulas and figures
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Enter the coefficients and coordinates, and you get the distance from a point \(\mathrm{P}(x_0,\ y_0)\) to a line \(ax + by + c = 0\) on the spot (the length of the perpendicular from the point to the line, which is the shortest distance)
- The answer is shown both as an exact value with a rationalized denominator, such as \(\dfrac{7\sqrt{5}}{5}\), and as a decimal (12 significant digits)
- Besides the distance, you also get the coordinates of the foot of the perpendicular \(\mathrm{H}\) (the point on the line closest to \(\mathrm{P}\)) and the equation of the perpendicular line itself
- You can enter the line in general form \(ax + by + c = 0\) or in slope-intercept form \(y = mx + k\) (for slope-intercept form, the steps also show how to rewrite it in general form)
- The distance between two parallel lines \(ax + by + c_1 = 0\) and \(ax + by + c_2 = 0\) can be found on the same screen
- You can check the result on a figure of the coordinate plane. A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are also on this page
What is this calculation used for?
The location your phone or car GPS receives can be off by several feet to over a hundred feet. If the app simply plotted that point, you might appear inside a building or in the middle of a field. So map apps calculate the distance from the measured point to each nearby road (on the map, a set of line segments) and move the point onto the closest road. This is called map matching, and the distance from a point to a line is at its core.
If the app also finds the foot of the perpendicular, it knows exactly where on that road you are, so it can tell you how far it is to the next turn.
Building plans have grid lines, and road and railway designs have a centerline. The positions of columns, walls, curbs and stakes are given as "how far from the reference line". This offset is exactly the distance from a point to a line. On site, surveyors calculate it from coordinates measured with a total station and check it against the design value.
Placing a curb at half the road width from the centerline is the same calculation repeated along the road.
A classification method called the support vector machine draws a line (a plane in higher dimensions) between two groups of data. It picks the line that is as far as possible from the data points of both groups, and that "how far" is the distance from a point to a line. Choosing the line with the widest gap (margin) is believed to make fewer mistakes on data the model has not seen yet.
It has been a standard method for spam filtering and image classification since before deep learning spread, and it is still a strong choice when there is little training data.
Lane detection in self-driving cars and straightening a scanned document both need the line that best fits a set of detected points. How well a line fits is measured by adding up the squared distances from each point to the line, and the line with the smallest total is chosen.
RANSAC, a method that fits a line while ignoring outliers, also uses the point-to-line distance: points within a set distance of the line count as fitting it.
When you zoom out on a map app, small bends in coastlines and roads are dropped automatically. This uses the Ramer–Douglas–Peucker algorithm. It finds the point farthest from the straight line joining the two ends of a path. If that distance is smaller than a set limit, all the points in between are dropped; if not, the path is split at that point and the check is repeated.
The shape still looks right with far less data, because the algorithm measures "how far off the line" each point is with a proper distance.
Formulas and figures
Symbols and terms
Symbols
| \(d\) | dee | A letter often used for distance, from the first letter of "distance". On this page it is the distance from the point to the line (the length of the perpendicular). |
| \(a,\ b,\ c\) | a, b, c | The coefficients of the line \(ax + by + c = 0\). \(a\) is the number in front of \(x\), \(b\) the number in front of \(y\), and \(c\) the number-only term (the constant). Letters from the start of the alphabet are usually used for fixed numbers. |
| \(x_0,\ y_0\) | x naught, y naught | The coordinates of the point \(\mathrm{P}\) you measure from. The small 0 at the lower right is a subscript. It shows that this is the coordinate of one fixed point, not the variable \(x\). (Also read "x sub zero".) |
| \(\mathrm{P},\ \mathrm{H},\ \mathrm{A}\) | P, H, A | Names of points. \(\mathrm{P}\) is for "point". \(\mathrm{H}\) is a common label for the foot of the perpendicular (think of the foot of a height). \(\mathrm{A}\) is a helper point taken on the line. |
| \(\left|\ \right|\) | absolute value | The absolute value sign. A positive number stays as it is; a negative number loses its minus sign (\(|-7| = 7\)). A distance is never negative, so the formula takes the absolute value of the plugged-in value. |
| \(\sqrt{\ }\) | square root | The square root sign: the number (0 or greater) that gives the number inside when squared. \(\sqrt{5}\) is the number whose square is 5. The sign is said to come from a stretched letter r, for "radix" (root). |
| \(\vec{n}\) | vector n | The normal vector: a vector that points perpendicular to the line. The letter n comes from "normal" (perpendicular). For the line \(ax + by + c = 0\), \(\vec{n} = (a,\ b)\). |
| \(\left|\vec{n}\right|\) | magnitude of vector n | The magnitude of a vector (the length of the arrow). For \(\vec{n} = (a,\ b)\), \(|\vec{n}| = \sqrt{a^2 + b^2}\). This is the denominator of the distance formula. |
| \(\vec{n}\cdot\overrightarrow{\mathrm{AP}}\) | n dot AP | The dot product of two vectors: multiply matching components and add (for \((a,\ b)\) and \((p,\ q)\), it is \(ap + bq\)). It shows how much the two directions line up. The raised dot is a different operation from ordinary multiplication. |
| \(t\) | tee | The scale factor that tells how many copies of the normal vector you move from \(\mathrm{P}\) to reach the line. The letter \(t\) (from "time") is commonly used for a number that can vary like this. |
| \(m,\ k\) | m, k | The slope and the y-intercept in slope-intercept form \(y = mx + k\). \(m\) is the usual letter for slope. Textbooks usually write the y-intercept as \(b\) (\(y = mx + b\)), but this page uses \(k\) so it is not confused with the \(b\) of the general form. |
| \(c_1,\ c_2\) | c one, c two | The constants of the two parallel lines. The small numbers at the lower right are subscripts that tell the first line from the second. |
| \(\ell_1,\ \ell_2\) | ell one, ell two | Names of lines. A script letter \(\ell\), from the first letter of "line", is commonly used for lines. |
Terms
| distance from a point to a line | The length of the perpendicular from the point to the line. It is shorter than the distance to any other point on the line, so it is also the shortest distance between the point and the line. It is usually taught in high school geometry or precalculus. |
| perpendicular | A line or segment that meets another line at a right angle. If you drop a perpendicular from a point to a line, its length is the distance from the point to the line. |
| foot of the perpendicular | The point where the perpendicular from a point meets the original line. It is the spot on the line closest to that point. |
| general form | Writing the equation of a line as \(ax + by + c = 0\). Vertical lines (such as \(x = 3\)) can be written this way too, so every line fits the same form. (Some textbooks call \(ax + by = c\) the standard form; it is the same line with the constant moved to the right side.) |
| slope-intercept form | Writing the equation of a line as \(y = mx + k\) (in most textbooks \(y = mx + b\)). You can see the slope and where the line crosses the \(y\)-axis at a glance, but vertical lines cannot be written this way. |
| normal vector | A vector pointing perpendicular to a line (or a plane). The normal vector of the line \(ax + by + c = 0\) is \((a,\ b)\). The point-to-line distance formula finds the length measured in the direction of this normal vector. |
| dot product | A calculation that makes one number from two vectors: multiply matching components and add (\((a,\ b)\cdot(p,\ q) = ap + bq\)). It also equals \(|\vec{u}||\vec{v}|\cos\theta\). If it is 0, the two vectors are perpendicular. |
| projection | The shadow of one vector cast straight onto the direction of another vector (also called the orthogonal projection). The distance from a point to a line is the length of the shadow of \(\overrightarrow{\mathrm{AP}}\) in the direction of the normal vector. |
| absolute value | The size of a number without its sign. It is the distance from 0 on the number line (\(|-7| = 7\), \(|7| = 7\)). A distance is never negative, so the formula uses the absolute value. |
| rationalizing the denominator | Removing a root from the denominator by multiplying the numerator and denominator by the same number. For example, multiply both parts of \(\dfrac{7}{\sqrt{5}}\) by \(\sqrt{5}\) to get \(\dfrac{7\sqrt{5}}{5}\). It is taught in Algebra 1 or Algebra 2, and final answers are usually written this way. |
| parallel | Two lines that never meet, however far you extend them. For \(a_1x + b_1y + c_1 = 0\) and \(a_2x + b_2y + c_2 = 0\), the lines are parallel or the same when the ratios of the \(x\) and \(y\) coefficients are equal (as an equation, \(a_1b_2 - a_2b_1 = 0\)). If the constants follow the same ratio too, the two lines lie on top of each other. |
| reflection | The point you get by flipping a point across a line, like a mirror image. Once you know the foot of the perpendicular \(\mathrm{H}\), the reflection of \(\mathrm{P}\) is \(2\mathrm{H} - \mathrm{P}\). |
| coordinate plane | A plane with an \(x\)-axis and a \(y\)-axis, where each point is written as a pair \((x,\ y)\). It lets you turn geometry problems into calculations. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back to review these topics is the fastest way forward.
| The coordinate plane and coordinates of points (Grades 5–6) |
|
| Equations of lines (Grade 8 and Algebra 1) |
|
| Square roots and rationalizing the denominator (Algebra 1 and Algebra 2) |
|
| Absolute value (Grades 6–7) |
|
| The Pythagorean theorem and the distance formula (Grade 8 and Geometry) |
|
| Vectors and the dot product (Precalculus) |
|
How to calculate it in Excel
| x coefficient a | 1 |
| y coefficient b | 2 |
| Constant c | -3 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Numerator |a*x0+b*y0+c| | =ABS(B1*B4+B2*B5+B3) |
| Denominator √(a^2+b^2) | =SQRT(B1^2+B2^2) |
| Distance d | =B6/B7 |
| x coefficient a | 1 |
| y coefficient b | 2 |
| x-coordinate of point A on the line | 3 |
| y-coordinate of point A on the line | 0 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Dot product n·AP | =B1*(B5-B3)+B2*(B6-B4) |
| Length of the normal vector |n| | =SQRT(B1^2+B2^2) |
| Distance d | =ABS(B7)/B8 |
| Slope m | 2 |
| y-intercept k | 1 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Distance d | =ABS(B1*B3-B4+B2)/SQRT(B1^2+1) |
| x coefficient a | 1 |
| y coefficient b | 2 |
| Constant c | -3 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Scale factor t | =(B1*B4+B2*B5+B3)/(B1^2+B2^2) |
| x-coordinate of H | =B4-B1*B6 |
| y-coordinate of H | =B5-B2*B6 |
| x coefficient a | 1 |
| y coefficient b | 2 |
| 1st line's constant c1 | -3 |
| 2nd line's constant c2 | 7 |
| Distance d | =ABS(B3-B4)/SQRT(B1^2+B2^2) |
"^" is a power, ABS gives the absolute value, and SQRT gives the square root.
The first table is the example of the point (4, 3) and the line x + 2y - 3 = 0. The numerator is 7, the denominator is about 2.2360679775, and the distance is about 3.1304951685.
The second table checks that the same distance comes from "dot product of the normal vector and AP ÷ length of the normal vector". The dot product is 7, and the distance is about 3.1304951685, the same as in the first table.
The third table is the example of the point (4, 3) and the line y = 2x + 1. The distance is about 2.683281573.
The fourth table gives 1.4, 2.6 and 0.2, so the foot of the perpendicular is (2.6, 0.2) = (13/5, 1/5).
The fifth table is the distance between x + 2y - 3 = 0 and x + 2y + 7 = 0. The answer is about 4.472135955.
How to calculate it in Google Sheets
| x coefficient a | 1 |
| y coefficient b | 2 |
| Constant c | -3 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Numerator |a*x0+b*y0+c| | =ABS(B1*B4+B2*B5+B3) |
| Denominator √(a^2+b^2) | =SQRT(B1^2+B2^2) |
| Distance d | =B6/B7 |
| x coefficient a | 1 |
| y coefficient b | 2 |
| x-coordinate of point A on the line | 3 |
| y-coordinate of point A on the line | 0 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Dot product n·AP | =B1*(B5-B3)+B2*(B6-B4) |
| Length of the normal vector |n| | =SQRT(B1^2+B2^2) |
| Distance d | =ABS(B7)/B8 |
| Slope m | 2 |
| y-intercept k | 1 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Distance d | =ABS(B1*B3-B4+B2)/SQRT(B1^2+1) |
| x coefficient a | 1 |
| y coefficient b | 2 |
| Constant c | -3 |
| x-coordinate of P | 4 |
| y-coordinate of P | 3 |
| Scale factor t | =(B1*B4+B2*B5+B3)/(B1^2+B2^2) |
| x-coordinate of H | =B4-B1*B6 |
| y-coordinate of H | =B5-B2*B6 |
| x coefficient a | 1 |
| y coefficient b | 2 |
| 1st line's constant c1 | -3 |
| 2nd line's constant c2 | 7 |
| Distance d | =ABS(B3-B4)/SQRT(B1^2+B2^2) |
How to calculate it in Python
from fractions import Fraction
# Line ax + by + c = 0 (a fraction such as 3/4 can be written as Fraction(3, 4))
a = Fraction(1)
b = Fraction(2)
c = Fraction(-3)
# Coordinates of point P
x0 = Fraction(4)
y0 = Fraction(3)
# The point plugged into the equation (with its sign) and the squared length of the normal vector
substituted = a * x0 + b * y0 + c
square = a * a + b * b
distance = abs(float(substituted)) / float(square) ** 0.5
print(f"Numerator |a*x0+b*y0+c| = {abs(substituted)}")
print(f"Denominator √(a^2+b^2) = √{square}")
print(f"Distance d = {distance}")
# Foot of the perpendicular H (move back t times the normal vector)
t = substituted / square
foot_x = x0 - a * t
foot_y = y0 - b * t
print(f"Scale factor t = {t}")
print(f"Foot of the perpendicular H = ({foot_x}, {foot_y})")
How to write it in LaTeX and other math languages (copy and paste)
d = |a·x₀ + b·y₀ + c| ÷ √(a² + b²)
d = \frac{\left|a x_0 + b y_0 + c\right|}{\sqrt{a^{2} + b^{2}}}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>d</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>|</mo>
<mi>a</mi><msub><mi>x</mi><mn>0</mn></msub>
<mo>+</mo>
<mi>b</mi><msub><mi>y</mi><mn>0</mn></msub>
<mo>+</mo>
<mi>c</mi>
<mo>|</mo>
</mrow>
<msqrt>
<mrow>
<msup><mi>a</mi><mn>2</mn></msup>
<mo>+</mo>
<msup><mi>b</mi><mn>2</mn></msup>
</mrow>
</msqrt>
</mfrac>
</mrow>
</math>
d = abs(a*x_0 + b*y_0 + c)/sqrt(a^2 + b^2)
d = Abs[a x0 + b y0 + c]/Sqrt[a^2 + b^2]
d := abs(a*x0 + b*y0 + c)/sqrt(a^2 + b^2);
d = abs(a*x0 + b*y0 + c)/sqrt(a^2 + b^2);
d = |a x_0+b y_0+c|/√(a^2+b^2)
d = |n·AP| ÷ |n|
d = \frac{\left|\vec{n}\cdot\overrightarrow{\mathrm{AP}}\right|}{\left|\vec{n}\right|}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>d</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>|</mo>
<mover><mi>n</mi><mo>→</mo></mover>
<mo>⋅</mo>
<mover><mrow><mi>A</mi><mi>P</mi></mrow><mo>→</mo></mover>
<mo>|</mo>
</mrow>
<mrow>
<mo>|</mo>
<mover><mi>n</mi><mo>→</mo></mover>
<mo>|</mo>
</mrow>
</mfrac>
</mrow>
</math>
d = abs(vec n * vec(AP))/abs(vec n)
d = Abs[n . ap]/Norm[n]
d := abs(DotProduct(n, ap))/Norm(n, 2);
d = abs(dot(n, ap))/norm(n);
d = |n\vec ∙AP\vec |/|n\vec |
d = |m·x₀ − y₀ + k| ÷ √(m² + 1)
d = \frac{\left|m x_0 - y_0 + k\right|}{\sqrt{m^{2} + 1}}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>d</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>|</mo>
<mi>m</mi><msub><mi>x</mi><mn>0</mn></msub>
<mo>−</mo>
<msub><mi>y</mi><mn>0</mn></msub>
<mo>+</mo>
<mi>k</mi>
<mo>|</mo>
</mrow>
<msqrt>
<mrow>
<msup><mi>m</mi><mn>2</mn></msup>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msqrt>
</mfrac>
</mrow>
</math>
d = abs(m*x_0 - y_0 + k)/sqrt(m^2 + 1)
d = Abs[m x0 - y0 + k]/Sqrt[m^2 + 1]
d := abs(m*x0 - y0 + k)/sqrt(m^2 + 1);
d = abs(m*x0 - y0 + k)/sqrt(m^2 + 1);
d = |m x_0-y_0+k|/√(m^2+1)
H = (x₀ − t·a, y₀ − t·b) t = (a·x₀ + b·y₀ + c) ÷ (a² + b²)
\mathrm{H} = \left(x_0 - t a,\ y_0 - t b\right),\quad t = \frac{a x_0 + b y_0 + c}{a^{2} + b^{2}}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi mathvariant="normal">H</mi>
<mo>=</mo>
<mo>(</mo>
<mrow><msub><mi>x</mi><mn>0</mn></msub><mo>−</mo><mi>t</mi><mi>a</mi></mrow>
<mo>,</mo>
<mrow><msub><mi>y</mi><mn>0</mn></msub><mo>−</mo><mi>t</mi><mi>b</mi></mrow>
<mo>)</mo>
<mo>,</mo>
<mi>t</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mi>a</mi><msub><mi>x</mi><mn>0</mn></msub>
<mo>+</mo>
<mi>b</mi><msub><mi>y</mi><mn>0</mn></msub>
<mo>+</mo>
<mi>c</mi>
</mrow>
<mrow>
<msup><mi>a</mi><mn>2</mn></msup>
<mo>+</mo>
<msup><mi>b</mi><mn>2</mn></msup>
</mrow>
</mfrac>
</mrow>
</math>
H = (x_0 - t*a, y_0 - t*b), t = (a*x_0 + b*y_0 + c)/(a^2 + b^2)
t = (a x0 + b y0 + c)/(a^2 + b^2); h = {x0 - t a, y0 - t b}
t := (a*x0 + b*y0 + c)/(a^2 + b^2); H := [x0 - t*a, y0 - t*b];
t = (a*x0 + b*y0 + c)/(a^2 + b^2); H = [x0 - t*a, y0 - t*b];
H = (x_0-t a, y_0-t b), t = (a x_0+b y_0+c)/(a^2+b^2)
d = |c₁ − c₂| ÷ √(a² + b²)
d = \frac{\left|c_1 - c_2\right|}{\sqrt{a^{2} + b^{2}}}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>d</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>|</mo>
<msub><mi>c</mi><mn>1</mn></msub>
<mo>−</mo>
<msub><mi>c</mi><mn>2</mn></msub>
<mo>|</mo>
</mrow>
<msqrt>
<mrow>
<msup><mi>a</mi><mn>2</mn></msup>
<mo>+</mo>
<msup><mi>b</mi><mn>2</mn></msup>
</mrow>
</msqrt>
</mfrac>
</mrow>
</math>
d = abs(c_1 - c_2)/sqrt(a^2 + b^2)
d = Abs[c1 - c2]/Sqrt[a^2 + b^2]
d := abs(c1 - c2)/sqrt(a^2 + b^2);
d = abs(c1 - c2)/sqrt(a^2 + b^2);
d = |c_1-c_2|/√(a^2+b^2)
How to have ChatGPT do the calculation
You are a math assistant for coordinate geometry. Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing). For the point (4, 3) and the line x + 2y - 3 = 0, find: 1. The distance from the point to the line (as an exact value with a rationalized denominator, and as a decimal) 2. The coordinates of the foot of the perpendicular from the point to the line (as reduced fractions) 3. The equation of that perpendicular (the line through the point, perpendicular to the given line) In Python, use the fractions module from the standard library and sympy to calculate exactly. Show the formulas you used and the numbers from the execution result.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
