First, let's see it in action. Here are two points (you can drag them) and the equation of the line through them. Explanations follow.
../geometry/images/geom-line-equn.js
The Points
We use Cartesian Coordinates to mark a point on a graph by how far along and how far up it is:
Example: The point (12,5) is 12 units along, and 5 units up
Steps
There are 3 steps to find the Equation of the Straight Line :
- 1. Find the slope of the line
- 2. Put the slope and one point into the "Point-Slope Formula"
- 3. Simplify
Step 1: Find the Slope (or Gradient) from 2 Points
What is the slope (or gradient) of this line?
We know two points:
- point "A" is (6,4) (at x is 6, y is 4)
- point "B" is (2,3) (at x is 2, y is 3)
The slope is the change in height divided by the change in horizontal distance.
Looking at this diagram ...
Slope m = change in ychange in x = yA − yBxA − xB
In other words, we:
- subtract the Y values,
- subtract the X values
- then divide
Like this:
m = change in y change in x = 4−3 6−2 = 1 4 = 0.25
It doesn't matter which point comes first, it still works out the same. Try swapping the points:
m = change in y change in x = 3−4 2−6 = −1 −4 = 0.25
Same answer.
Step 2: The "Point-Slope Formula"
Now put that slope and one point into the "Point-Slope Formula"
Start with the "point-slope" formula (x1 and y1 are the coordinates of a point on the line):
y − y1 = m(x − x1)
We can choose any point on the line for x1 and y1, so let's just use point (2,3):
y − 3 = m(x − 2)
We already calculated the slope "m":
m = change in ychange in x = 4−36−2 = 14
And we have:
y − 3 = 14(x − 2)
That is an answer, but we can simplify it further.
Step 3: Simplify
Start with:y − 3 = 14(x − 2)
Multiply 14 by (x−2):y − 3 = x4 − 24
Add 3 to both sides:y = x4 − 24 + 3
Simplify:y = x4 + 52
And we get:
y = x4 + 52
Which is now in the Slope-Intercept (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
Example: What is the equation of this line?
Start with the "point-slope" formula:
y − y1 = m(x − x1)
Put in these values:
- x1 = 1
- y1 = 6
- m = (2−6)/(3−1) = −4/2 = −2
And we get:
y − 6 = −2(x − 1)
Simplify to Slope-Intercept (y = mx + b) form:
y − 6 = −2x + 2
y = −2x + 8
DONE!
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 = yA − yBxA − xB = 4 − 12 − 2 = 30 = undefined
But there is still a way of writing the equation: use x= instead of y=, like this:
x = 2
7270, 525, 526, 1165, 1166, 7291, 7292, 7300, 7301, 7302
Equation of a Straight Line Straight Line Graph Calculator Algebra Index
To find the solution, we can use the slope-intercept formula which is y=mx + b. Here, m is the slope which has formula
m=(y2-y1)/(x2-x1) and b is the y-intercept.
Let us find the slope first. Using our two points we get m=(y2-y1)/(x2-x1) = (4--2)/(-3-5) = 6/-8 which reduces to -3/4.
Yes1 Yes2Yes3 Yes4Yes3 Yes6Yes3 Yes8Yes3 /* C++ program to find if line passing through0
/* C++ program to find if line passing through1
/* C++ program to find if line passing through3 /* C++ program to find if line passing through4
/* C++ program to find if line passing through5
/* C++ program to find if line passing through6
Yes3 /* C++ program to find if line passing through8
/* C++ program to find if line passing through1
0 1 2 3 4
5 6 7 8
0two coordinates also passes through origin0
5 6two coordinates also passes through origin3 8
0/* C++ program to find if line passing through3 two coordinates also passes through origin7
/* C++ program to find if line passing through5
Java
two coordinates also passes through origin9
0
1
2 3
4 5
0
0 8 9 Yes2Yes3 Yes4Yes3 Yes6
or not */5Yes3 Yes8Yes3 /* C++ program to find if line passing through0
0/* C++ program to find if line passing through1
#include <bits/stdc++.h>2/* C++ program to find if line passing through3 /* C++ program to find if line passing through4
0/* C++ program to find if line passing through5
0/* C++ program to find if line passing through6
0using0 8 using2 using3
0/* C++ program to find if line passing through1
#include <bits/stdc++.h>2 1 using8using9namespace0namespace1namespace0namespace3namespace0namespace5namespace6 3 4
namespace9Yes00 7Yes02
#include <bits/stdc++.h>2two coordinates also passes through origin0
namespace9Yes00two coordinates also passes through origin3Yes02
0/* C++ program to find if line passing through5
/* C++ program to find if line passing through5
Yes12
Python3
Yes13
Yes14
Yes15
Yes16 Yes17
0/* C++ program to find if line passing through3 Yes20Yes21 Yes22Yes23 Yes24Yes25Yes25 Yes27Yes21 Yes29Yes23 Yes31
0
Yes33
1 using8using9namespace0namespace1namespace0namespace3namespace0namespace5 4Yes25Yes25 Yes46Yes47
0Yes49Yes50 7 4
two coordinates also passes through origin0Yes54
0Yes49Yes50two coordinates also passes through origin3 4
0
Yes61
Yes62
C#
Yes63
0
1
using Yes67
4 5
0 8 Yes1 Yes2Yes3 Yes4Yes3 Yes6
Yes78Yes3 Yes8Yes3 /* C++ program to find if line passing through0
0/* C++ program to find if line passing through1
#include <bits/stdc++.h>2/* C++ program to find if line passing through3 /* C++ program to find if line passing through4
0/* C++ program to find if line passing through5
0/* C++ program to find if line passing through6
0using0 8 using2 Yes96
0/* C++ program to find if line passing through1
#include <bits/stdc++.h>2 1 2 3 4
namespace9/* C++ program to find if line passing through05 7Yes02
#include <bits/stdc++.h>2two coordinates also passes through origin0
namespace9/* C++ program to find if line passing through05two coordinates also passes through origin3Yes02
0/* C++ program to find if line passing through5
/* C++ program to find if line passing through5
/* C++ program to find if line passing through17
PHP
/* C++ program to find if line passing through18
/* C++ program to find if line passing through19
/* C++ program to find if line passing through20
/* C++ program to find if line passing through21
/* C++ program to find if line passing through22
1
/* C++ program to find if line passing through24 Yes2/* C++ program to find if line passing through26namespace0/* C++ program to find if line passing through28namespace0
/* C++ program to find if line passing through30/* C++ program to find if line passing through31namespace0/* C++ program to find if line passing through33 4
/* C++ program to find if line passing through1
0/* C++ program to find if line passing through3 Yes50/* C++ program to find if line passing through26 /* C++ program to find if line passing through40/* C++ program to find if line passing through33 Yes23/* C++ program to find if line passing through28namespace6
/* C++ program to find if line passing through45/* C++ program to find if line passing through28 /* C++ program to find if line passing through40/* C++ program to find if line passing through31 Yes23/* C++ program to find if line passing through26/* C++ program to find if line passing through51
/* C++ program to find if line passing through5
/* C++ program to find if line passing through6
1 /* C++ program to find if line passing through55
0/* C++ program to find if line passing through57Yes50 7Yes02
two coordinates also passes through origin0
0/* C++ program to find if line passing through57Yes50two coordinates also passes through origin3Yes02
Yes12
/* C++ program to find if line passing through68
Javascript
/* C++ program to find if line passing through69
/* C++ program to find if line passing through70
0
1
0/* C++ program to find if line passing through24 /* C++ program to find if line passing through75
0/* C++ program to find if line passing through1
#include <bits/stdc++.h>2/* C++ program to find if line passing through3 /* C++ program to find if line passing through4
0/* C++ program to find if line passing through5
/* C++ program to find if line passing through83
/* C++ program to find if line passing through84
#include <bits/stdc++.h>2 1 2 3 4
namespace9/* C++ program to find if line passing through91 7Yes02
#include <bits/stdc++.h>2two coordinates also passes through origin0
namespace9/* C++ program to find if line passing through91two coordinates also passes through origin3Yes02
00
00 02
03
Output: Yes
Time Complexity: O(1)
Auxiliary Space: O(1)
This article is contributed by Aarti_Rathi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above