Equations of a Straight Line

In the applet below, lines can be dragged as a whole or with one of the two defining points. When a line is dragged or clicked upon, one of its equations is displayed just beneath the graph. With the Reduce box checked, the equation appears in its simplest form. The applet can display several lines simultaneously. To obtain additional lines, check the Duplicate box and start dragging one of the already present lines to the desired position. In fact, you'll be dragging a newly created copy of that line.

As of 2018, Java plugins are not supported by any browsers (find out more). This Wolfram Demonstration, Two Points Determine a Line, shows an item of the same or similar topic, but is different from the original Java applet, named 'LinearFunc'. The originally given instructions may no longer correspond precisely.

(image below from deprecated 'LinearFunc' applet)

equations of linear function

Below I give several forms of the equation of a straight line depending on the attributes it is defined with. In every case, the verification is straightforward. Plug in the data and see that it satisfies the equation. All the equations below are derived in the usual Cartesian coordinate system.

Line through two points

The line through two distinct points (x1, y1) and (x2, y2) is given by

(1) y = y1 + [(y2 - y1) / (x2 - x1)]·(x - x1),

where x1 and x2 are assumed to be different. In case they are equal, the equation is simplified to

x = x1

and does not require a second point.

Equation (1) can also be written as

y - y1 = [(y2 - y1) / (x2 - x1)]·(x - x1),

or even as

(x2 - x1)·(y - y1) = (y2 - y1)·(x - x1),

where one does not have to worry whether x1 = x2 or not. However, the simplest for me to remember is this

(y - y1)/(y2 - y1) = (x - x1)/(x2 - x1)

which is not as universal is the one before.

General equation

A straight line is defined by a linear equation whose general form is

Ax + By + C = 0,

where A, B are not both 0.

The coefficients A and B in the general equation are the components of vector n = (A, B) normal to the line. The pair r = (x, y) can be looked at in two ways: as a point or as a radius-vector joining the origin to that point. The latter interpretation shows that a straight line is the locus of points r with the property

r·n = const.

That is a straight line is a locus of points whose radius-vector has a fixed scalar product with a given vector n, normal to the line. To see why the line is normal to n, take two distinct but otherwise arbitrary points r1 and r2 on the line, so that

r1·n = r2·n.

But then we conclude that

(r1 - r2n = 0.

In other words the vector r1 - r2 that joins the two points and thus lies on the line is perpendicular to n.

Normalized equation

The norm ||n|| of a vector n = (A, B) is defined via ||n||2 = A2 + B2 and has the property that, for any non-trivial vector n, n/||n|| is a unit vector, i.e., || n/||n|| || = 1.

Note that the line defined by a general equation would not change if the equation were to be multiplied by a non-zero coefficient. This property can be used to keep the coefficient A non-negative. It can also be used to normalize the equation by dividing it by ||n||. As a result, in a normalized equation

Ax + By + C = 0,

A2 + B2 = 1.

(In the applet, the coefficients of the normalized equation are rounded to up to 6 digits, for which reason the above identity may only hold approximately.)

The normalized equation is conveniently used in determining the distance from a point to a line.


Assume a straight line intersects x-axis at (a, 0) and y-axis at (0, b). Then it is defined by the equation

x/a + y/b = 1,

which also can be written as

xb + ya = ab.

The latter form is somewhat more general as it allows either a or b to be 0. a and b are defined as x-intercept and y-intercept of the linear function. These are signed distances from the points of intersection of the line with the axes.


The equation of a straight line through point (a, b) with a given slope of m is

y = m(x - a) + b, or y - b = m(x - a).

As a particular case, we have

Slope-intercept equation

The equation of a line with a given slope m and the y-intercept b is

y = mx + b.

This is obtained from the point-slope equation by setting a = 0. It must be understood that the point-slope equation can be written for any point on the line, meaning that the equation in this form is not unique. The slope-intercept equation is unique because if the uniqueness for the line of the two parameters: slope and y-intercept.

Parametric equation

A line through point r0 = (a, b) parallel to vector u = (u, v) is given by

(x, y) = (a, b) + t·(u, v),

where t is any real number. In the vector form, we have

r = r0 + t·u,

where r = (x, y).

Implicit equation

A line through point r0 = (a, b) perpendicular to vector n = (m, n) is given by

m(x - a) + n(y - b) = 0,

or if we take r = (x, y), a generic point on the line, we see that

n·(r - r0) = 0,

where dots indicates the scalar product of two vectors.

A function whose graph is a straight line is linear and continuous.

Related material

  • What Is Line?
  • Functions, what are they?
  • Cartesian Coordinate System
  • Addition and Subtraction of Functions
  • Function, Derivative and Integral
  • Graph of a Polynomial of arbitrary degree
  • Graph of a Polynomial Defined by Its Roots
  • Inflection Points of Fourth Degree Polynomials
  • Lagrange Interpolation (an Interactive Gizmo)
  • Taylor Series Approximation to Cosine
  • Taylor Series Approximation to Cosine
  • Linear Function with Coefficients in Arithmetic Progression
  • Sine And Cosine Are Continuous Functions
  • 71674721

    |Contact| |Front page| |Contents|

    Copyright © 1996-2018 Alexander Bogomolny