Equation of a Line from 2 Points
Example: The point (12,5) is
12 units along, and 5 units up
Coordinates
We use Cartesian Coordinates to mark a point on a graph by how far along and how far up it is:
What it Looks Like
With 2 points we can work out the Equation of the Straight Line that goes through them.
Here is a demo of what it looks like. Try dragging the points.
OK, let's discover how to create the equation. First, find the slope ...
Finding Slope (or Gradient) from 2 Points
What is the slope (or gradient) of this line?We know two points:

The slope is the change in height divided by the change in horizontal distance.
Looking at this diagram ...
... the formula is: Slope m = \frac{change in y}{change in x} = \frac{y_{A} − y_{B}}{x_{A} − x_{B}} 
So we:
 subtract the Y values,
 subtract the X values
 then divide
Like this:
m = \frac{change in y}{change in x} = \frac{4−3}{6−2} = \frac{1}{4} = 0.25
It doesn't matter which point comes first, it still works out the same. Try swapping the points:
m = \frac{change in y}{change in x} = \frac{3−4}{2−6} = \frac{−1}{−4} = 0.25
Finding an Equation from 2 Points
Now we have found the slope we can look at finding the whole equation.
What is the equation of this line?

The easiest method is to start with the "pointslope" formula:
y − y_{1} = m(x − x_{1})
We can choose any point on the line as being point "1", so let us just use point (2,3):
y − 3_{} = m(x − 2_{})
Use the formula from above for the slope "m":
Slope m = \frac{change in y}{change in x} = \frac{4−3}{6−2} = \frac{1}{4}
And we have:
y − 3_{} = (1/4)(x − 2_{})
That is an acceptable answer, but we could simplify it further:
y − 3_{} = x/4 − 2/4
y = x/4 − ½_{} + 3
y = x/4 + 5/2
Which is now in the "SlopeIntercept (y = mx + b)" form.
Check It!
Let us confirm by testing with the second point (6,4):
y = x/4 + 5/2 = 6/4 + 2.5 = 1.5 + 2.5 = 4
Yes, when x=6 then y=4, so it works!
Another Example
What is the equation of this line?

Start with the "pointslope" formula:
y − y_{1} = m(x − x_{1})
Put in these values:
 x_{1} = 1
 y_{1} = 6
 m = (2−6)/(3−1) = −4/2 = −2
And we get:
y − 6_{} = −2(x − 1_{})
We can change it to "SlopeIntercept (y = mx + b)" form:
y − 6_{} = −2x + 2
y = −2x + 8
The Big Exception
The previous method works nicely except for one particular case: a vertical line:
A vertical line's gradient is undefined (because we cannot divide by 0): m = \frac{y_{A} − y_{B}}{x_{A} − x_{B}} = \frac{4 − 1}{2 − 2} = \frac{3}{0} = undefined But there is still a way of writing the equation: use x= instead of y=, like this: x = 2 