Skip to main content

Writing a Line Equation from Two Endpoints

This article starts with coordinates and the linear functions learned in middle school. Our question is: given the two endpoints of a segment, how can we use an equation to describe its containing line?

First Understand What It Means for a Point to Satisfy an Equation​

The point (1,3)(1,3) has horizontal coordinate 11 and vertical coordinate 33. Below, XX denotes the horizontal coordinate and YY the vertical coordinate. These capital letters work just like the lowercase x,yx,y in textbooks.

Consider this equation:

Y=2X+1.Y=2X+1.

It says: the vertical coordinate is 22 times the horizontal coordinate, plus 11.

Horizontal coordinate XXCalculate the vertical coordinate Y=2X+1\teachBlue{Y}=\teachBlue{2X+1}Resulting point
002×0+1=12\times0+1=1(0,1)(0,1)
112×1+1=32\times1+1=3(1,3)(1,3)
222×2+1=52\times2+1=5(2,5)(2,5)
332×3+1=72\times3+1=7(3,7)(3,7)

The four dots below plot the four points in the table. They all lie on the blue line. A cross additionally marks (2,6)(2,6) for comparison.

Four dots, (0,1), (1,3), (2,5), and (3,7), lie on Y=2X+1. The cross at (2,6) is 1 above (2,5) at the same horizontal coordinate and is not on the line.Four dots, (0,1), (1,3), (2,5), and (3,7), lie on Y=2X+1. The cross at (2,6) is 1 above (2,5) at the same horizontal coordinate and is not on the line.

Look at X=2X=2 in the figure. The equation requires Y=2×2+1=5Y=2\times2+1=5, so (2,5)(2,5) lies on the line. The point (2,6)(2,6), which is 11 higher, does not, since 6≠2×2+16\ne2\times2+1. Sharing a horizontal coordinate does not mean both points satisfy the equation; the vertical coordinate must also meet its requirement.

Only finitely many points are marked. From linear functions in middle school, we know that letting XX range over all real numbers, including negative numbers and decimals, gives an entire straight line as the graph of Y=2X+1Y=2X+1.

This equality is therefore called the line's “equation.” To test whether a point lies on the line, substitute both coordinates and check whether the equality holds.

How Can We Find the Equation from Two Endpoints?​

Now reverse the question. Given only the endpoints A=(1,3)\teachBlue{A}=(1,3) and B=(3,7)\teachBlue{B}=(3,7), how do we find the equation of their line?

First consider how much each coordinate changes from AA to BB. The dashed lines split the change into two parts: move right by 3−1=23-1=2, then up by 7−3=47-3=4. These are auxiliary reading guides, not the original segment.

Move horizontally right from A=(1,3) to (3,3), increasing the horizontal coordinate by 2, then vertically up to B=(3,7), increasing the vertical coordinate by 4. The slope of line AB is 4 divided by 2, which equals 2.Move horizontally right from A=(1,3) to (3,3), increasing the horizontal coordinate by 2, then vertically up to B=(3,7), increasing the vertical coordinate by 4. The slope of line AB is 4 divided by 2, which equals 2.

Two distinct points determine a line. Since this line is not vertical, start with the linear-function form

Y=kX+d.Y=kX+d.

Here k,dk,d are two unknown numbers. Textbooks often use bb for the last number. We use dd for now because bb will appear in another form later.

The line passes through A=(1,3)A=(1,3), so substitution must give a true equation:

3=k+d.3=k+d.

It also passes through B=(3,7)B=(3,7), so

7=3k+d.7=3k+d.

Subtract the first equation from the second to eliminate dd:

7−3=(3k+d)−(k+d),7-3=(3k+d)-(k+d),

which gives 4=2k4=2k. The 44 and 22 are exactly the upward and rightward changes in the figure: a horizontal increase of 22 gives a vertical increase of 2k2k, and we know that increase is 44. Divide both sides by 22 to obtain k=2k=2. This number is the “slope.” Here it means moving 11 to the right along the line takes us 22 upward.

Substitute back into 3=k+d3=k+d to get 3=2+d3=2+d. Subtract 22 from both sides to obtain d=1d=1.

The line equation is therefore

Y=2X+1.Y=2X+1.

Why Also Write aX+bY=c?​

Rewrite the same equation. First move 2X2X to the left:

Y−2X=1.Y-2X=1.

Then multiply both sides by −1-1:

2X−Y=−1.2X-Y=-1.

Neither transformation changes the equation's solutions, so it still describes the same line.

Call the number before XX by the name aa, the number before YY by bb, and the number on the right by cc. Then we can write the general form

aX+bY=c.aX+bY=c.

In 2X−Y=−12X-Y=-1, we have a=2a=2, b=−1b=-1, and c=−1c=-1. Remember that −Y-Y means (−1)×Y(-1)\times Y, so bb is −1-1 here.

a,b,ca,b,c are three fixed numbers; X,YX,Y are the coordinates of a point on the line and can vary.

Can We Calculate a, b, c Directly from the Endpoints?​

Yes, without first finding k,dk,d in the linear-function form. However, “calculate” does not mean that there is only one possible triple a,b,ca,b,c. We need to find a triple making aX+bY=caX+bY=c describe the line through the two endpoints.

Keep using A=(1,3)A=(1,3) and B=(3,7)B=(3,7). Start with the equalities these two points must satisfy, rather than rushing to memorize a formula.

What Requirements Do the Two Points Place on a and b?​

The line passes through A=(1,3)A=(1,3), so substituting X=1X=1, Y=3Y=3 into aX+bY=caX+bY=c must make the equality true:

a×1+b×3=c.a\times1+b\times3=c.

That is,

a+3b=c.a+3b=c.

The line also passes through B=(3,7)B=(3,7). Substituting X=3X=3, Y=7Y=7 gives

a×3+b×7=c,a\times3+b\times7=c,

or

3a+7b=c.3a+7b=c.

Both equations have the same number cc on the right. Subtract the first from the second to eliminate it:

(3a+7b)−(a+3b)=c−c.(3a+7b)-(a+3b)=c-c.

Remove the parentheses. When subtracting an entire parenthesized expression, change the signs of both terms:

3a+7b−a−3b=0.3a+7b-a-3b=0.

Group the aa terms and the bb terms:

(3a−a)+(7b−3b)=0.(3a-a)+(7b-3b)=0.

Combine like terms:

2a+4b=0.2a+4b=0.

Look back at the dashed-line diagram. From AA to BB, the horizontal coordinate increases by 3−1=23-1=2 and the vertical coordinate by 7−3=47-3=4. Thus the total change in aX+bYaX+bY is 2a+4b2a+4b. Both substituted points must give the same cc, so this change must equal 00.

Find One Triple, Then See Why It Is Not Unique​

Starting from 2a+4b=02a+4b=0, subtract 4b4b from both sides:

2a=−4b.2a=-4b.

Divide both sides by the nonzero number 22:

a=−2b.a=-2b.

This says that once we choose bb, aa is −2-2 times bb. It does not prescribe a particular value for bb.

In this example, we cannot choose b=0b=0, because that would also make a=0a=0. Substituting an endpoint would then give c=0c=0, and the equation would become 0=00=0. Every point satisfies it, so it cannot describe the line we want.

First choose an easy value, b=−1b=-1. Substitute into a=−2ba=-2b:

a=(−2)×(−1)=2.a=(-2)\times(-1)=2.

The equation is now

2X−Y=c.2X-Y=c.

Only cc remains unknown. The first point (1,3)(1,3) lies on the line, so substituting its coordinates must make the equation true:

2×1−3=c.2\times1-3=c.

First multiply to get 2−3=c2-3=c, then subtract to get −1=c-1=c, or c=−1c=-1. We have found an equation:

2X−Y=−1.2X-Y=-1.

Check the second point (3,7)(3,7): the left side is 2×3−7=6−7=−12\times3-7=6-7=-1, equal to the right side too.

Multiplying both sides of this equation by 22 gives

2(2X−Y)=2×(−1).2(2X-Y)=2\times(-1).

Expand the left side using the distributive law and calculate the right side:

4X−2Y=−2.4X-2Y=-2.

Now a=4a=4, b=−2b=-2, and c=−2c=-2. Multiplication by 22 can be reversed by dividing both sides by 22, so exactly the same points satisfy the two equations. (2,−1,−1)(2,-1,-1) and (4,−2,−2)(4,-2,-2) are different coefficient triples describing the same line.

Choose a and b Directly to Avoid That Division​

We first chose b=−1b=-1 and later multiplied the whole equation by 22 to explain why the coefficients are not unique. In an actual calculation, we can directly choose a=4a=4, b=−2b=-2 from the latter triple.

Why choose these numbers? Look again at the condition imposed by the endpoints:

2a+4b=0.2a+4b=0.

We want the two terms on the left to cancel. Multiplication is commutative: 2×42\times4 equals 4×24\times2. Therefore, choosing a=4a=4 in the first term and b=−2b=-2 in the second makes the left side

2×4+4×(−2)=8+(−8)=0.2\times4+4\times(-2)=8+(-8)=0.

This is a choice requiring no division: take aa as the change in vertical coordinate, and bb as the negative of the change in horizontal coordinate. Here the vertical change is 7−3=47-3=4, so a=4a=4. The horizontal change is 3−1=23-1=2, whose negative is −(3−1)=−2-(3-1)=-2, so b=−2b=-2. We can also write that negative as 1−31-3, which explains the reversed subtraction order in the second coefficient.

Having chosen these two numbers, the equation is temporarily

4X−2Y=c.4X-2Y=c.

The right side cc must equal the value obtained by substituting any point on the line into the left side. We already know the first point (1,3)(1,3) lies on the line, so use it to calculate. Substitute X=1X=1, Y=3Y=3:

c=4×1+(−2)×3.c=4\times1+(-2)\times3.

First calculate the two products: 4×1=44\times1=4 and (−2)×3=−6(-2)\times3=-6. Then add:

c=4+(−6)=−2.c=4+(-6)=-2.

We are not multiplying the coordinates of the two different points together. We multiply the first point's horizontal coordinate by aa, its vertical coordinate by bb, and add the results. Using the second point also works: 4×3+(−2)×7=12+(−14)=−24\times3+(-2)\times7=12+(-14)=-2, the same result.

Write This Choice as a General Formula​

First name the coordinates of the two points:

SymbolMeaningValue in this example
X1X_1Horizontal coordinate of the first point11
Y1Y_1Vertical coordinate of the first point33
X2X_2Horizontal coordinate of the second point33
Y2Y_2Vertical coordinate of the second point77

The subscripts 1,21,2 are just labels distinguishing the two points; X1X_1 does not mean X×1X\times1.

Write the first point as (X1,Y1)(X_1,Y_1) and the second as (X2,Y2)(X_2,Y_2). From the first to the second, the horizontal change is X2−X1X_2-X_1 and the vertical change is Y2−Y1Y_2-Y_1.

Following the choice above, first take aa as the vertical change:

a=Y2−Y1,a=Y_2-Y_1,

then take bb as the negative of the horizontal change. Removing parentheses preceded by a minus sign changes both signs:

b=−(X2−X1)=X1−X2.b=-(X_2-X_1)=X_1-X_2.

Finally, because the first point is on the line, substitute X=X1X=X_1, Y=Y1Y=Y_1 into aX+bY=caX+bY=c to obtain

c=a×X1+b×Y1.c=a\times X_1+b\times Y_1.

Omitting multiplication signs, the last line is c=aX1+bY1c=aX_1+bY_1. It still means “substitute the first point into the left side to calculate what the right side must be.”

The endpoints must be distinct so that a,ba,b are not both 00. If a=Y2−Y1=0a=Y_2-Y_1=0, their vertical coordinates are equal. If b=X1−X2=0b=X_1-X_2=0, their horizontal coordinates are equal too. If both hold, the points coincide.

These three steps use only addition, subtraction, and multiplication. Integer endpoint coordinates therefore give integer a,b,ca,b,c. Next we prove why the method works in general and check vertical and horizontal lines.

Why Do These Three Steps Always Work?​

Repeat the earlier calculation of k,dk,d, now using coordinates for the two points. First consider the case where their horizontal coordinates differ.

Both points lie on Y=kX+dY=kX+d, so substituting each gives

Y1=kX1+d,Y2=kX2+d.Y_1=kX_1+d,\qquad Y_2=kX_2+d.

Subtract the first equation from the second to eliminate dd:

Y2−Y1=k(X2−X1).Y_2-Y_1=k(X_2-X_1).

Since X2−X1X_2-X_1 is nonzero, divide both sides by it:

k=Y2−Y1X2−X1.k=\frac{Y_2-Y_1}{X_2-X_1}.

Now take any point (X,Y)(X,Y) on the line. Subtract the first endpoint's equation Y1=kX1+dY_1=kX_1+d from its equation Y=kX+dY=kX+d, again eliminating dd:

Y−Y1=k(X−X1).Y-Y_1=k(X-X_1).

Substitute the value of kk just found:

Y−Y1=Y2−Y1X2−X1(X−X1).Y-Y_1=\frac{Y_2-Y_1}{X_2-X_1}(X-X_1).

Multiply both sides by X2−X1X_2-X_1 to clear the denominator:

(X2−X1)(Y−Y1)=(Y2−Y1)(X−X1).(X_2-X_1)(Y-Y_1)=(Y_2-Y_1)(X-X_1).

Expand both sides with the distributive law:

(X2−X1)Y−(X2−X1)Y1=(Y2−Y1)X−(Y2−Y1)X1.(X_2-X_1)Y-(X_2-X_1)Y_1 =(Y_2-Y_1)X-(Y_2-Y_1)X_1.

Move the terms containing X,YX,Y to the left and the remaining terms to the right:

(Y2−Y1)X−(X2−X1)Y=(Y2−Y1)X1−(X2−X1)Y1.(Y_2-Y_1)X-(X_2-X_1)Y =(Y_2-Y_1)X_1-(X_2-X_1)Y_1.

Note that −(X2−X1)=X1−X2-(X_2-X_1)=X_1-X_2. Thus the coefficient of XX on the left is exactly a=Y2−Y1a=Y_2-Y_1, and the coefficient of YY is exactly b=X1−X2b=X_1-X_2. The right side is aX1+bY1aX_1+bY_1, which is cc.

This gives aX+bY=caX+bY=c. The subtraction order in the formula comes from rearranging the equation; it is not arbitrary.

Does This Also Work for Vertical and Horizontal Lines?​

Yes for vertical lines, but they need a separate explanation. We divided by X2−X1X_2-X_1 above. Two points on a vertical line have equal horizontal coordinates, and division by 00 is not allowed.

The figure below places the two special cases in one coordinate system. First consider the vertical blue line. From (2,1)(2,1) to (2,4)(2,4), the vertical coordinate changes, but the horizontal coordinate remains 22, so its equation is X=2\teachBlue{X}=\teachBlue{2}.

The vertical line X=2 passes through (2,1) and (2,4), keeping the horizontal coordinate fixed. The horizontal line Y=3 passes through (1,3) and (4,3), keeping the vertical coordinate fixed.The vertical line X=2 passes through (2,1) and (2,4), keeping the horizontal coordinate fixed. The horizontal line Y=3 passes through (1,3) and (4,3), keeping the vertical coordinate fixed.

This also explains why Y=kX+dY=kX+d cannot describe a vertical line: when X=2X=2, the right side produces only one value, 2k+d2k+d, which cannot equal both 11 and 44 from the figure.

Apply the three-step formula:

a=4−1=3,b=2−2=0,c=3×2+0×1=6.a=4-1=3,\qquad b=2-2=0,\qquad c=3\times2+0\times1=6.

We obtain 3X+0Y=63X+0Y=6, or X=2X=2, which is correct. For any two distinct endpoints with the same horizontal coordinate, b=0b=0 and a≠0a\ne0. The equation becomes aX=aX1aX=aX_1; dividing by aa gives X=X1X=X_1.

Horizontal lines work too. Consider the horizontal orange line: from (1,3)(1,3) to (4,3)(4,3), the horizontal coordinate changes but the vertical coordinate stays 33, so the equation should be Y=3\teachOrange{Y}=\teachOrange{3}.

Substitution into the formula gives a=0a=0, b=−3b=-3, and c=−9c=-9. The equation is therefore −3Y=−9-3Y=-9, or Y=3Y=3.

Thus aX+bY=caX+bY=c expresses ordinary slanted lines, horizontal lines, and vertical lines in the same form.

Finally, Distinguish Two Issues​

The endpoints must be distinct points. If they coincide, the formula gives a=b=c=0a=b=c=0 and the equation becomes 0=00=0. Every point satisfies it, so it cannot specify a particular line. The geometry agrees: through a single known point, we can draw many different lines.

A line equation describes the entire extended line. In the figure below, the thick solid part is only the segment from A=(1,3)A=(1,3) to B=(3,7)B=(3,7). Dashed portions at both ends show that the line continues.

Segment AB is thick and solid; the line beyond its endpoints is dashed. P=(4,9) lies on the extension beyond B. Projections of A and B onto the horizontal axis mark the segment's horizontal range from 1 to 3, including both ends.Segment AB is thick and solid; the line beyond its endpoints is dashed. P=(4,9) lies on the extension beyond B. Projections of A and B onto the horizontal axis mark the segment's horizontal range from 1 to 3, including both ends.

Consider P=(4,9)P=(4,9) in the figure. Substitution gives 9=2×4+19=2\times4+1, a true equality, so it lies on the line. But it is beyond BB, outside the thick solid segment.

Follow the two vertical guides downward: the horizontal coordinates of A,BA,B are 1,31,3. Therefore this example requires both

Y=2X+1,1≤X≤3,Y=2X+1,\qquad 1\le X\le3,

to describe the original segment. The two equality signs in the bounds include its endpoints. The equation determines the line containing the points; the coordinate bounds then select which part of it to take. We use horizontal bounds here because this line is not vertical. For a vertical line, use the endpoints' vertical coordinates to bound the segment instead.

With these coefficients understood, continue to Integer Scaling and Intersection Denominators to see how they are used to compute the intersection of two lines.