Skip to main content
Home
Pimath

Menu EN

  • Home
  • 🌐 EN
    • 🇮🇹 IT
    • 🇪🇸 ES
    • 🇵🇹 PT
    • 🇫🇷 FR
    • 🇷🇴 RO
  • 👨‍🎓 About Me
  • 🚧 Theory & Exercises
User account menu
  • Log in

Breadcrumb

  1. Home

Equation of a Line: Formulas, Derivations and Exercises

Profile picture for user Pimath
By Pimath, 1 June, 2025

The straight line is one of the fundamental objects of Euclidean geometry. In the Cartesian plane, a straight line can be described by means of 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 implicit form, encompasses every straight line in the plane, including vertical and horizontal lines.

When the line is not vertical, its equation may also be written in the form

\[ y=mx+q, \]

called the explicit form. Here \(m\) is the slope (or gradient), which describes the inclination of the line relative to the horizontal axis, while \(q\) is the \(y\)-intercept, that is, the \(y\)-coordinate of the point at which the line meets the \(y\)-axis.

In this article we shall see how to derive the equation of a line through two given points, how to pass from the implicit to the explicit form, what the geometric meaning of the slope is, how to determine a line perpendicular to a given line, and how to write the parametric equation of a line.


Contents

  • Equation of the line through two points
  • Explicit form of the line
  • Implicit form of the line
  • Geometric meaning of the slope
  • Parametric equation of the line
  • Line perpendicular to a given line
  • Practice problems on the straight line

Equation of the line through two points

Suppose we know 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 nonzero.

If \(x_1=x_2\), the two points share 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 on the line, distinct from \(P_1\). The following figure illustrates this situation:

Graph of the line through two points in the Cartesian plane

The right triangles \(\triangle P_1P'P\) and \(\triangle P_1P'_2P_2\) are similar, since each has a right angle and they have a congruent acute angle determined by the inclination of the line. Taking the horizontal and vertical variations with their signs into account, the similarity of the triangles yields 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 the line. Expanding, we obtain

\[ y-y_1=mx-mx_1, \]

hence

\[ y=mx+(y_1-mx_1). \]

Setting

\[ q=y_1-mx_1, \]

we obtain the explicit form

\[ y=mx+q. \]

From the point-slope form we may also obtain an implicit 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 obtain

\[ (x_2-x_1)(y-y_1)=(y_2-y_1)(x-x_1). \]

Bringing every term to the left-hand side and rearranging, we get:

\[ (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 appeal to vectors. A generic point \(P(x,y)\) lies on 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 gives

\[ (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. \]

Explicit form of the line

A line in the Cartesian plane admits an explicit form whenever it is not vertical. In this case its equation may be written as

\[ y=mx+q. \]

The number \(m\) is the slope of the line and measures the variation of the \(y\)-coordinate relative to the variation of the \(x\)-coordinate. The number \(q\) is the \(y\)-intercept, that is, the \(y\)-coordinate 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)\) on 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. \]

Implicit form of the line

The implicit 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: for 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 implicit form is the most general form of 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 explicit 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 implicit form is particularly useful because it allows one to check readily 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. \]

Moreover, starting from the point-slope form

\[ y-y_1=m(x-x_1), \]

one can obtain an implicit form by bringing every term 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\) describes how much \(y\) changes as \(x\) changes. For this reason the slope is also called the gradient of the line.

If the line has explicit 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 \(x\)-axis.
Equation of the line with positive slope
  • If \(m<0\), the line is decreasing: as \(x\) increases, \(y\) decreases. In this case the line forms an obtuse angle with the positive \(x\)-axis.
Equation of the line with negative slope
  • If \(m=0\), the line is horizontal. Indeed, the equation becomes \(y=q\), so the ordinate remains constant as \(x\) varies.
Equation of the line with slope equal to zero

The slope is also related to the angle of inclination of the line. If \(\alpha\) is the angle that the line forms with the positive \(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 not defined, because the abscissa is constant and it is not possible to express \(y\) as a function of \(x\). Geometrically, the vertical line is parallel to the \(y\)-axis.

Equation of the line with undefined slope

Parametric equation of the line

A line may also be described by means of a parametric equation. In this form, the coordinates of the points on the line depend on a real parameter.

Suppose the line passes through a point

\[ P_0(x_0,y_0) \]

and has as direction vector a nonzero 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\) in the interval \([0,1]\) describe the points of the segment \(P_1P_2\), whereas the remaining values of \(t\) describe 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 the slopes, provided neither line is vertical.

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\) through a point \(P_0(x_0,y_0)\), one therefore uses 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, it has equation \(y=k\). Every line perpendicular to \(r\) is vertical, with equation \(x=h\).
  • If \(r\) is vertical, it has equation \(x=h\). Every line perpendicular to \(r\) is horizontal, with equation \(y=k\).

More generally, using the implicit form, the line

\[ ax+by+c=0 \]

has normal vector

\[ \boldsymbol{n}=(a,b). \]

A line perpendicular to it therefore has a direction parallel to the vector \((a,b)\). For this reason, 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 holds equally well when the original line is vertical or horizontal.

Practice problems on the straight line

We conclude with some practice problems on the equation of the straight line. The 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. Determine the explicit 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. \]

Practice problems on the straight line

Problem 2. Determine 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 gives:

\[ y=-\frac{1}{2}x+\frac{3}{2}+6. \]

Hence

\[ y=-\frac{1}{2}x+\frac{15}{2}. \]

The explicit equation of the required line is

\[ y=-\frac{1}{2}x+\frac{15}{2}. \]

In implicit 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. \]

Practice problems on the straight line

Problem 3. Determine the equation of the line through the point \(P(3,4)\) with angle of inclination \(30^\circ\) relative to the positive \(x\)-axis.

The slope of a non-vertical line is related to the 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. \]

Practice problems on the straight line

Problem 4. Determine 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 explicit equation of the required line is

\[ y=-\frac{1}{2}x+4. \]

In implicit 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. \]

Practice problems on the straight line

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 the first equation for \(t\):

\[ 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 explicit form of the line is

\[ y=2x-7. \]

Bringing every term to the left-hand side, we obtain the implicit form:

\[ 2x-y-7=0. \]

Let us verify that the line passes through both points:

\[ A(3,-1):\quad -1=2\cdot 3-7, \]

\[ B(4,1):\quad 1=2\cdot 4-7. \]

Practice problems on the straight line

Your feedback is important to us! Leave a comment and help us improve this content. Thank you!

Feedback

Support us by liking the page:
Or, share:

Tags

  • Analytic geometry

Support us by liking the page:
Or, share:

Copyright © 2026 | Pimath | All Rights Reserved