Given two points P and Q in the coordinate plane, find the equation of the line passing through both the points.
This kind of conversion is very useful in many geometric algorithms like intersection of lines, finding the circumcenter of a triangle, finding the incenter of a triangle and many more…
Input : P(3, 2) Q(2, 6) Output : 4x + 1y = 14 Input : P(0, 1) Q(2, 4) Output : 3x + -2y = -2
Let the given two points be P(x1, y1) and Q(x2, y2). Now, we find the equation of line formed by these points.
Any line can be represented as,
ax + by = c
Let the two points satisfy the given line. So, we have,
ax1 + by1 = c
ax2 + by2 = c
We can set the following values so that all the equations hold true,
a = y2 - y1 b = x1 - x2 c = ax1 + by1
These can be derived by first getting the slope directly and then finding the intercept of the line. OR these can also be derived cleverly by a simple observation as under:
ax1 + by1 = c ...(i) ax2 + by2 = c ...(ii) Equating (i) and (ii), ax1 + by1 = ax2 + by2 => a(x1 - x2) = b(y2 - y1) Thus, for equating LHS and RHS, we can simply have, a = (y2 - y1) AND b = (x1 - x2) so that we have, (y2 - y1)(x1 - x2) = (x1 - x2)(y2 - y1) AND Putting these values in (i), we get, c = ax1 + by1
Thus, we now have the values of a, b and c which means that we have the line in the coordinate plane.
The line passing through points P and Q is: 4x + 1y = 14
This article is contributed by Aanya Jindal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to find equation of a plane passing through 3 points
- Maximum distinct lines passing through a single point
- Find the equation of plane which passes through two points and parallel to a given axis
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Check if a line passes through the origin
- Determine the number of squares of unit area that a given line will pass through.
- Maximum number of line intersections formed through intersection of N planes
- Find points at a given distance on a line of given slope
- Number of Integral Points between Two Points
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Minimum number of points to be removed to get remaining points on one side of axis
- Ways to choose three points with distance between the most distant points <= L
- Count maximum points on same line
- Represent a given set of points by the best possible straight line
- Number of horizontal or vertical line segments to connect 3 points
- Number of ordered points pair satisfying line equation
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Check whether a straight line can be formed using N co-ordinate points
- Slope of the line parallel to the line with the given slope
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference