A line is one of the fundamental objects of Euclidean geometry. In the Cartesian plane, a line can be described by a first-degree equation in the two variables \(x\) and \(y\), that is, by an equation of the form
\[ ax+by+c=0, \]
where \(a,b,c\in\mathbb{R}\) and the coefficients \(a\) and \(b\) are not both zero. This form, called the general form, encompasses every line in the plane, including vertical and horizontal lines.
When the line is not vertical, its equation can also be written in the form
\[ y=mx+q, \]
called the slope-intercept form. Here \(m\) is the slope, which describes the inclination of the line with respect to the \(x\)-axis, while \(q\) is the \(y\)-intercept, that is, the ordinate of the point at which the line meets the \(y\)-axis.
On this page we shall see how to derive the equation of a line through two given points, how to pass from the general form to the slope-intercept form, what the slope means geometrically, how to determine a line perpendicular to a given line, and how to write the parametric equation of a line.
Contents
- Equation of a line through two points
- Slope-intercept form of a line
- General form of a line
- Geometric meaning of the slope
- Parametric equation of a line
- Line perpendicular to a given line
- Practice problems on the line
Equation of the line through two points
Suppose we are given two distinct points of the Cartesian plane:
\[ P_1(x_1,y_1),\qquad P_2(x_2,y_2). \]
Since the two points are distinct, at least one of the two differences \(x_2-x_1\) and \(y_2-y_1\) is non-zero.
If \(x_1=x_2\), the two points have the same abscissa. In this case the line through \(P_1\) and \(P_2\) is vertical and has equation
\[ x=x_1. \]
Suppose now that \(x_1\ne x_2\). In this case the line is not vertical, and we may introduce the slope
\[ m=\frac{y_2-y_1}{x_2-x_1}. \]
If \(y_1=y_2\), then \(m=0\) and the line is horizontal. In this case its equation is
\[ y=y_1. \]
Suppose then that \(y_1\ne y_2\). The line is oblique, and we may derive its equation using the similarity of right triangles. Let \(P(x,y)\) be a generic point of the line, distinct from \(P_1\). The following figure illustrates this situation:

The right triangles \(\triangle P_1P'P\) and \(\triangle P_1P'_2P_2\) are similar, since they have a right angle and a congruent acute angle, determined by the inclination of the line. Taking the horizontal and vertical displacements with their signs, the similarity of the triangles gives the ratio
\[ \frac{y-y_1}{x-x_1}=\frac{y_2-y_1}{x_2-x_1}. \]
Since
\[ m=\frac{y_2-y_1}{x_2-x_1}, \]
it follows that
\[ y-y_1=m(x-x_1). \]
This is the point-slope form of the equation of a line. Expanding, we obtain
\[ y-y_1=mx-mx_1, \]
hence
\[ y=mx+(y_1-mx_1). \]
Setting
\[ q=y_1-mx_1, \]
we recover the slope-intercept form
\[ y=mx+q. \]
Starting from the point-slope form, we can also obtain a general form. Indeed,
\[ y-y_1=\frac{y_2-y_1}{x_2-x_1}(x-x_1). \]
Multiplying both sides by \(x_2-x_1\), we get
\[ (x_2-x_1)(y-y_1)=(y_2-y_1)(x-x_1). \]
Bringing all terms to the left-hand side and rearranging, we obtain
\[ (y_1-y_2)x+(x_2-x_1)y+(x_1y_2-x_2y_1)=0. \]
This formula was derived under the assumption \(x_1\ne x_2\). Nevertheless, it remains valid for any pair of distinct points: it covers the oblique case, the horizontal case, and also the vertical case.
To justify this general validity, we may argue with vectors. A generic point \(P(x,y)\) belongs to the line through \(P_1\) and \(P_2\) if and only if the three points \(P_1\), \(P_2\), and \(P\) are collinear. This occurs precisely when the vectors
\[ \overrightarrow{P_1P}=(x-x_1,y-y_1), \qquad \overrightarrow{P_1P_2}=(x_2-x_1,y_2-y_1) \]
are linearly dependent. In algebraic terms, this condition is equivalent to the vanishing of the determinant
\[ \begin{vmatrix} x-x_1 & y-y_1\\ x_2-x_1 & y_2-y_1 \end{vmatrix}=0. \]
Expanding the determinant, we obtain
\[ (x-x_1)(y_2-y_1)-(y-y_1)(x_2-x_1)=0, \]
and hence, once again,
\[ (y_1-y_2)x+(x_2-x_1)y+(x_1y_2-x_2y_1)=0. \]
Slope-intercept form of a line
A line in the Cartesian plane admits a slope-intercept form if and only if it is not vertical. In this case its equation can be written as
\[ y=mx+q. \]
The number \(m\) is the slope of the line and measures the variation of the ordinate relative to the variation of the abscissa. The number \(q\) is the \(y\)-intercept, that is, the ordinate of the point at which the line meets the \(y\)-axis.
Indeed, setting \(x=0\) in the equation \(y=mx+q\), we obtain
\[ y=q. \]
Hence the line meets the \(y\)-axis at the point
\[ (0,q). \]
If we know a point \(P_1(x_1,y_1)\) of the line together with the slope \(m\), we may use the point-slope form:
\[ y-y_1=m(x-x_1). \]
Expanding, we obtain
\[ y-y_1=mx-mx_1, \]
and hence
\[ y=mx+(y_1-mx_1). \]
Thus, in the form \(y=mx+q\), we have
\[ q=y_1-mx_1. \]
If instead two distinct points \(P_1(x_1,y_1)\) and \(P_2(x_2,y_2)\) are known, with \(x_1\ne x_2\), then the slope is
\[ m=\frac{y_2-y_1}{x_2-x_1}. \]
The condition \(x_1\ne x_2\) is essential: if \(x_1=x_2\), the line through the two points is vertical and cannot be written in the form \(y=mx+q\). In that case its equation is
\[ x=x_1. \]
General form of a line
The general form of the equation of a line is
\[ ax+by+c=0, \]
where \(a,b,c\in\mathbb{R}\) and \(a\) and \(b\) are not both zero. The condition
\[ (a,b)\ne(0,0) \]
is necessary: indeed, if \(a=0\) and \(b=0\), the equation would no longer depend on \(x\) and \(y\). If \(c=0\), it would be satisfied by every point of the plane; if \(c\ne0\), it would be satisfied by no point at all. In either case it would not represent a line.
The general form is the most general expression for the equation of a line in the Cartesian plane, since it also encompasses vertical lines, which cannot be written in the form \(y=mx+q\).
If \(b\ne 0\), we may solve for \(y\):
\[ by=-ax-c, \]
hence
\[ y=-\frac{a}{b}x-\frac{c}{b}. \]
In this case the line is not vertical, and its slope-intercept form is
\[ y=mx+q, \]
with
\[ m=-\frac{a}{b}, \qquad q=-\frac{c}{b}. \]
If instead \(b=0\), then necessarily \(a\ne 0\), and the equation becomes
\[ ax+c=0. \]
Solving for \(x\), we obtain
\[ x=-\frac{c}{a}. \]
This is the equation of a vertical line.
If \(a=0\), then necessarily \(b\ne 0\), and the equation becomes
\[ by+c=0. \]
Solving for \(y\), we obtain
\[ y=-\frac{c}{b}. \]
This is the equation of a horizontal line.
The general form is particularly useful because it allows one to check easily whether a point lies on a line. Indeed, a point \(P(x_0,y_0)\) lies on the line \(ax+by+c=0\) if and only if
\[ ax_0+by_0+c=0. \]
Furthermore, starting from the point-slope form
\[ y-y_1=m(x-x_1), \]
one can obtain a general form by bringing all terms to the left-hand side:
\[ y-y_1-mx+mx_1=0, \]
that is,
\[ -mx+y+(mx_1-y_1)=0. \]
Geometric meaning of the slope
The slope of a non-vertical line measures the ratio between the variation of the ordinate and the variation of the abscissa. If the line passes through two distinct points
\[ P_1(x_1,y_1),\qquad P_2(x_2,y_2), \]
with \(x_1\ne x_2\), then the slope is
\[ m=\frac{y_2-y_1}{x_2-x_1}. \]
This formula shows that \(m\) measures the change in \(y\) per unit change in \(x\). For this reason the slope is also called the gradient of the line.
If the line has the slope-intercept equation
\[ y=mx+q, \]
then the value of \(m\) determines the geometric behaviour of the line.
- If \(m>0\), the line is increasing: as \(x\) increases, \(y\) increases as well. In this case the line forms an acute angle with the positive direction of the \(x\)-axis.

- If \(m<0\), the line is decreasing: as \(x\) increases, \(y\) decreases. In this case the line forms an obtuse angle with the positive direction of the \(x\)-axis.

- If \(m=0\), the line is horizontal. Indeed the equation becomes \(y=q\), so the ordinate remains constant as \(x\) varies.

The slope is also linked to the angle of inclination of the line. If \(\alpha\) is the angle that the line forms with the positive direction of the \(x\)-axis, then, for a non-vertical line,
\[ m=\tan\alpha. \]
Vertical lines constitute a special case. A vertical line has equation
\[ x=k. \]
In this case the slope is undefined, because the abscissa is constant and it is not possible to express \(y\) as a function of \(x\). Geometrically, a vertical line is parallel to the \(y\)-axis.

Parametric equation of a line
A line can also be described by means of a parametric equation. In this form, the coordinates of the points of the line depend on a real parameter.
Suppose the line passes through a point
\[ P_0(x_0,y_0) \]
and has as its direction vector a non-zero vector
\[ \boldsymbol{v}=(a,b). \]
Then a parametric representation of the line is
\[ \begin{cases} x=x_0+at\\ y=y_0+bt \end{cases} \qquad t\in\mathbb{R}. \]
The parameter \(t\) indicates the displacement along the direction of the vector \(\boldsymbol{v}\). As \(t\) ranges over \(\mathbb{R}\), the point
\[ (x_0+at,\ y_0+bt) \]
traces out all and only the points of the line.
If two distinct points
\[ P_1(x_1,y_1),\qquad P_2(x_2,y_2), \]
are known, we may take as direction vector
\[ \boldsymbol{v}=(x_2-x_1,\ y_2-y_1). \]
In this case a parametric representation of the line through \(P_1\) and \(P_2\) is
\[ \begin{cases} x=x_1+(x_2-x_1)t\\ y=y_1+(y_2-y_1)t \end{cases} \qquad t\in\mathbb{R}. \]
For \(t=0\) one obtains the point \(P_1\), while for \(t=1\) one obtains the point \(P_2\). Values of \(t\) between \(0\) and \(1\) trace out the points of the segment \(P_1P_2\), while the remaining values of \(t\) trace out the points of the line lying outside the segment.
The parametric form is particularly useful because it describes oblique, horizontal, and vertical lines in exactly the same way. For instance, if the direction vector is \((0,b)\), with \(b\ne 0\), then the abscissa remains constant and one obtains a vertical line.
Line perpendicular to a given line
Two lines are perpendicular if they meet forming four right angles. In the Cartesian plane, this condition can be expressed simply in terms of slopes when both slopes are defined; the vertical and horizontal cases must be treated separately.
Suppose a line \(r\) has equation
\[ r:\ y=mx+q, \]
with \(m\ne 0\). Then every line perpendicular to \(r\) has slope
\[ m_\perp=-\frac{1}{m}. \]
Indeed, if two non-vertical lines have slopes \(m_1\) and \(m_2\), they are perpendicular if and only if
\[ m_1m_2=-1. \]
To find the line perpendicular to \(r\) and passing through a point \(P_0(x_0,y_0)\), we therefore use the point-slope form:
\[ y-y_0=-\frac{1}{m}(x-x_0). \]
The point \(P_0(x_0,y_0)\) is simply the point through which the perpendicular line must pass. It need not lie on the line \(r\).
We must, however, distinguish the special cases.
- If \(r\) is horizontal, then it has equation \(y=k\). The line perpendicular to \(r\) and passing through \(P_0(x_0,y_0)\) is vertical and has equation \(x=x_0\).
- If \(r\) is vertical, then it has equation \(x=h\). The line perpendicular to \(r\) and passing through \(P_0(x_0,y_0)\) is horizontal and has equation \(y=y_0\).
More generally, using the general form, the line
\[ ax+by+c=0 \]
has as its normal vector
\[ \boldsymbol{n}=(a,b). \]
A line perpendicular to it therefore has a direction parallel to the vector \((a,b)\). Hence, if it must pass through \(P_0(x_0,y_0)\), one possible parametric equation for it is
\[ \begin{cases} x=x_0+at\\ y=y_0+bt \end{cases} \qquad t\in\mathbb{R}. \]
This description is useful because it also works in the cases where the original line is vertical or horizontal.
Practice problems on the line
We conclude with some practice problems on the equation of a line. These examples show how to apply the formulas developed in the preceding sections: the equation through two points, the perpendicular line, the slope, and the parametric form.
Problem 1. Find the slope-intercept equation of the line through the points \(A(1,2)\) and \(B(3,6)\).
We compute the slope:
\[ m=\frac{6-2}{3-1}=\frac{4}{2}=2. \]
Since the line passes through \(A(1,2)\), we use the point-slope form:
\[ y-2=2(x-1). \]
Expanding, we obtain
\[ y-2=2x-2, \]
hence
\[ y=2x. \]
The equation of the required line is therefore
\[ y=2x. \]
Let us verify that both points lie on the line:
\[ A(1,2):\quad 2=2\cdot 1, \]
\[ B(3,6):\quad 6=2\cdot 3. \]

Problem 2. Find the equation of the line perpendicular to the line \(y=2x\) and passing through the point \(P(3,6)\).
The given line has slope
\[ m=2. \]
Since the required line must be perpendicular to the given line, its slope is
\[ m_\perp=-\frac{1}{m}=-\frac{1}{2}. \]
We now use the point-slope form with the point \(P(3,6)\):
\[ y-6=-\frac{1}{2}(x-3). \]
Expanding:
\[ y-6=-\frac{1}{2}x+\frac{3}{2}. \]
Adding \(6\) to both sides, we obtain
\[ y=-\frac{1}{2}x+\frac{3}{2}+6. \]
Hence
\[ y=-\frac{1}{2}x+\frac{15}{2}. \]
The slope-intercept equation of the required line is
\[ y=-\frac{1}{2}x+\frac{15}{2}. \]
In general form:
\[ 2y=-x+15, \]
that is,
\[ x+2y-15=0. \]
Let us verify that the line passes through \(P(3,6)\):
\[ 6=-\frac{1}{2}\cdot 3+\frac{15}{2} =-\frac{3}{2}+\frac{15}{2} =\frac{12}{2}=6. \]

Problem 3. Find the equation of the line through the point \(P(3,4)\) with an angle of inclination of \(30^\circ\) with respect to the positive direction of the \(x\)-axis.
The slope of a non-vertical line is related to its angle of inclination by
\[ m=\tan\alpha. \]
Here \(\alpha=30^\circ\), so
\[ m=\tan 30^\circ=\frac{\sqrt{3}}{3}. \]
We use the point-slope form with \(P(3,4)\):
\[ y-4=\frac{\sqrt{3}}{3}(x-3). \]
Expanding:
\[ y-4=\frac{\sqrt{3}}{3}x-\sqrt{3}. \]
Hence
\[ y=\frac{\sqrt{3}}{3}x+4-\sqrt{3}. \]
The equation of the required line is therefore
\[ y=\frac{\sqrt{3}}{3}x+4-\sqrt{3}. \]
Let us verify that the line passes through \(P(3,4)\):
\[ y=\frac{\sqrt{3}}{3}\cdot 3+4-\sqrt{3} =\sqrt{3}+4-\sqrt{3}=4. \]

Problem 4. Find the equation of the line perpendicular to the line \(y=2x\) and passing through the point \(P(4,2)\).
The line \(y=2x\) has slope
\[ m=2. \]
The perpendicular line therefore has slope
\[ m_\perp=-\frac{1}{2}. \]
Using the point-slope form with the point \(P(4,2)\), we obtain
\[ y-2=-\frac{1}{2}(x-4). \]
Expanding:
\[ y-2=-\frac{1}{2}x+2. \]
Hence
\[ y=-\frac{1}{2}x+4. \]
The slope-intercept equation of the required line is
\[ y=-\frac{1}{2}x+4. \]
In general form:
\[ 2y=-x+8, \]
that is,
\[ x+2y-8=0. \]
Let us verify that the line passes through \(P(4,2)\):
\[ 2=-\frac{1}{2}\cdot 4+4=-2+4=2. \]

Problem 5. Write the parametric equation of the line through \(A(3,-1)\) and \(B(4,1)\). Then derive the corresponding Cartesian equation.
We compute a direction vector of the line:
\[ \boldsymbol{v}=(4-3,\ 1-(-1))=(1,2). \]
A parametric representation of the line through \(A(3,-1)\) with direction vector \(\boldsymbol{v}=(1,2)\) is
\[ \begin{cases} x=3+t\\ y=-1+2t \end{cases} \qquad t\in\mathbb{R}. \]
To pass to the Cartesian form, we solve for \(t\) from the first equation:
\[ x=3+t, \]
hence
\[ t=x-3. \]
Substituting into the second equation:
\[ y=-1+2(x-3). \]
Expanding:
\[ y=-1+2x-6=2x-7. \]
Thus the slope-intercept form of the line is
\[ y=2x-7. \]
Bringing all terms to the left-hand side, we obtain the general form:
\[ 2x-y-7=0. \]
Let us verify that the line passes through the two points:
\[ A(3,-1):\quad -1=2\cdot 3-7, \]
\[ B(4,1):\quad 1=2\cdot 4-7. \]
