Line Equation Calculator

if we have points (x1,y1) and (x2,y2), then lets set up an equation.

We know that at x1 we want to be at y1, so that’s not too difficult to do.

f(x) = (x - x1) + y1

With this function for the value x1 it will output y1 so we know this crosses that point.

Now we need to make sure that the change in value when you increase or decrease x is going to make it so at x2 we are at y2.

To do this we use a multiplier for the increase or decrease, commonly called the slope of a function.

f(x) = m(x - x1) + y1 where m is the slope / multiplier.

So for the function output we want to make it so when x is x2 then y2 = m * (x2 - x1) + y1.

Now we can just solve for m here using algebra.

Subtract y1 from both sides

y2 - y1 = m * (x2 - x1) + y1 - y1 = m * (x2 - x1)

(y2 - y1) / (x2 - x1) = m

This makes sense because what we’ve done is after this is divided and simplified, we’ve found the value of y that should increase or decrease per x value.

Also could be seen as the amount of y that goes into every x value, for instance if 1/2 is our m value, then when x increases by 1 the y value will increase by 1/2.

Anyways just trying to help you understand. Now we can plug this back in.

f(x) = (y2-y1)/(x2-x1) * (x - x1) + y1

We know that at x1 this is going to multiply and just end up being zero since zero multiplied by anything is zero. So good we still have y1 as our x1 value.

At x2 we can see that the denomenator / bottom part of our slope is going to equal since they’ll both be (x2-x1), so they cancel leaving us with f(x2) = y2-y1+y1

Which clearly simplifies to y2

Obviously this isnt practical to use this formula really outside of programming but it’s good to be able to understand it since it can help you understand stuff up to even calculus.

/r/askmath Thread