Equation of a line given two points

This online calculator finds the equation of a line given two points on that line, in slope-intercept and parametric forms

This page exists due to the efforts of the following people:

Timur

Timur

Created: 2019-02-18 11:54:45, Last updated: 2021-09-25 16:07:28

You can find an equation of a straight line given two points laying on that line. However, there exist different forms for a line equation. Here you can find two calculators for an equation of a line:

  • first calculator finds the line equation in slope-intercept form, that is,
    y=ax+b
    It also outputs slope and intercept parameters and displays the line on a graph.

  • second calculator finds the line equation in parametric form, that is,
    x=at+x_0\\y=bt+y_0
    It also outputs a direction vector and displays line and direction vector on a graph.

Also, the text and formulas below the calculators describe how to find the equation of a line from two points manually.

PLANETCALC, Slope-intercept line equation from two points

Slope-intercept line equation from two points

First Point

Second point

Line equation
 
Slope
 
Intercept
 
Digits after the decimal point: 2



PLANETCALC, Parametric line equation from two points

Parametric line equation from two points

First Point

Second point

Equation for x
 
Equation for y
 
Direction vector
 
Digits after the decimal point: 2

How to find the equation of a line in slope-intercept form

Let's find slope-intercept form of a line equation from the two known points (x_0, y_0) and (x_1, y_1).
We need to find slope a and intercept b.
For two known points we have two equations in respect to a and b
y_0=ax_0+b\\y_1=ax_1+b

Let's subtract the first from the second
y_1 - y_0=ax_1 - ax_0+b - b\\y_1 - y_0=ax_1 - ax_0\\y_1 - y_0=a(x_1 -x_0)
And from there
a=\frac{y_1 - y_0}{x_1 -x_0}

Note that b can be expressed like this
b=y-ax
So, once we have a, it is easy to calculate b simply by plugging x_0, y_0, a or x_1, y_1, a to the expression above.

Finally, we use the calculated a and b to write the result as
y=ax+b

Equation of a vertical line

Note that in the case of a vertical line, the slope and the intercept are undefined because the line runs parallel to the y-axis. The line equation, in this case, becomes x=x_1

Equation of a horizontal line

Note that in the case of a horizontal line, the slope is zero and the intercept is equal to the y-coordinate of points because the line runs parallel to the x-axis. The line equation, in this case, becomes y=y_1

How to find the slope-intercept equation of a line example

Problem: Find the equation of a line in the slope-intercept form given points (-1, 1) and (2, 4)
Solution:

  1. Calculate the slope a:
    a=\frac{y_1 - y_0}{x_1 -x_0} = \frac{4 - 1}{2 - (-1)} = \frac{3}{3} = 1
  2. Calculate the intercept b using coordinates of either point. Here we use the coordinates (-1, 1):
    b=y_0 - a x_0 = 1 - 1\cdot(-1)=2
  3. Write the final line equation (we omit the slope, because it equals one):
    y=x+2

And here is how you should enter this problem into the calculator above: slope-intercept line equation example

Parametric line equations

Let's find out parametric form of a line equation from the two known points (x_0, y_0) and (x_1, y_1).
We need to find components of the direction vector also known as displacement vector.
D=\begin{vmatrix}d_1\\d_2\end{vmatrix}=\begin{vmatrix}x_1-x_0\\y_1-y_0\end{vmatrix}
This vector quantifies the distance and direction of an imaginary motion along a straight line from the first point to the second point.

Once we have direction vector from x_0, y_0 to x_1, y_1, our parametric equations will be
x=d_1t+x_0\\y=d_2t+y_0
Note that if t = 0, then x = x_0, y = y_0 and if t = 1, then x = x_1, y = y_1

Equation of a vertical line

Note that in the case of a vertical line, the horizontal displacement is zero because the line runs parallel to the y-axis. The line equations, in this case, become
x=x_0\\y=d_2t+y_0

Equation of a horizontal line

Note that in the case of a horizontal line, the vertical displacement is zero because the line runs parallel to the x-axis. The line equations, in this case, become
x=d_1t+x_0\\y=y_0

How to find the parametric equation of a line example

Problem: Find the equation of a line in the parametric form given points (-1, 1) and (2, 4)
Solution:

  1. Calculate the displacement vector:
    D=\begin{vmatrix}d_1\\d_2\end{vmatrix}=\begin{vmatrix}x_1-x_0\\y_1-y_0\end{vmatrix}=\begin{vmatrix}2-(-1)\\4-1\end{vmatrix}=\begin{vmatrix}3\\3\end{vmatrix}
  2. Write the final line equations:
    x=3t-1\\y=3t+1
URL copied to clipboard
PLANETCALC, Equation of a line given two points

Comments