Check if three Straight Lines are Concurrent or Not


The problem includes checking if the three given straight lines are concurrent or not. If all three lines in a plane pass through the same point, they are said to be concurrent. They must intersect with each other exactly at one point to be concurrent.

The three concurrent lines are depicted in the above illustration. According to the above illustration, the point of intersection of any two lines should be located on the third line to be concurrent. The point of concurrence is the intersection of these lines.As everyone is aware, a straight line can be written as a general equation, such as $\mathrm{a_{1}x=b_{1}y+c_{1}=0}$ or $\mathrm{y=mx+c}$

In this issue, we'll take into account the first generalised equation of the straight line. The straight line's coefficients are referred to as a1, b1, and c1 in this equation, while x and y stand in for the coordinates of every point the line passes through.

We will be provided the coefficient values for three straight lines in this problem set. We must determine whether or not those lines are concurrent and print the output appropriately.

Let’s understand the problem better with some examples:

Input

a=2 , b=-3 , c=4
d=9 , e=5 , f=-19
g=2 , h=-7, i=12

Output

Yes

Explanation : The generalised form of a straight line is $\mathrm{a_{1}x=b_{1}y+c_{1}=0}$ . Here in the input a, b and c are the coefficients of the first straight line which can be written as 2x-3y+4=0 . Similarly d, e and f are the coefficients of the second line which is 9x+5y-19=0 and g, h and i are the coefficient of the third line 2x-7y+12=0 These three lines intersect at a point (1,2) which is the point of concurrency. Hence, the lines are concurrent.

Input

a=6 , b=3 , c=-12
d=2 , e=1 , f=-5
g=5 , h=-1 , i=14

Output

No

Explanation : Using the general equation of the straight line, we can find the equation of three straight lines given using their coefficients respectively. The three straight lines are 6x+3y-12 , 2x+y-5=0 . If we observe the first two lines, they have the same slopes which means they are parallel lines hence these three lines can never be concurrent lines as there is no common point of intersection.

We must develop an algorithm to examine whether the three lines given have any common points of intersection in order to resolve the aforementioned issue. Concurrent lines exist when all of the lines passes through a single point otherwise, they do not. Checking the common point of intersection using the algorithm is what we will do now.

Algorithm

The three equations of straight lines are assumed to be ax+by+c=0, dx+ey+f=0 and gx+hy+i=0 where a, b, c, d, e, f, g, h and i are the coefficients of the respective straight lines which will be provided as input. We need to check if these three lines have any common point of intersection.

The concurrent lines intersect only at one point. In mathematics, if three lines are concurrent then the value of determinant of a matrix formed by the coefficients of the three lines respectively will be 0.

The matrix formed by the coefficients of three lines will be:

$\mathrm{\begin{vmatrix}a & b & c\\d & e & f\\g & h & i \end{vmatrix}\:=\:0}$

The determinant of the above matrix will be zero if the given lines are concurrent.

We just need to calculate the value of the determinant of the matrix formed by the coefficients of the three lines to solve the problem.

The formula to calculate the determinant of the matrix is:

a ∗ (e ∗ i − f ∗ h) − b ∗ (d ∗ i − f ∗ g) + c ∗ (d ∗ h − e ∗ g) = determinant of matrix

When three line’s coefficient values are entered into the formula above, if the resultant value is 0, then the three lines are concurrent. The given lines are not concurrent lines if the determinant of the matrix has a value other than 0, according to mathematics.

To determine if the lines are concurrent or not, we shall use the formula above.

Approach

In order to solve the problem, we shall implement the aforementioned algorithm. In our approach, the following steps must be taken:

  • We'll write a function to determine if the given straight lines are concurrent.

  • Declare a variable, then set it to the value of the determinant of the matrix made up of the coefficients of the specified straight lines.

  • We'll check that the variable's value is 0. We will return true if the value is zero.

  • We will return false if any value other than 0 is contained in the variable's value.

  • If the function returns true, print the statement that the three lines are concurrent in the driver code else, print the statement that the three lines are not concurrent.

The C++ code for the approach:

Example

#include <bits/stdc++.h>

using namespace std;

//function to check if the three given lines are concurrent or not
bool check(int a, int b, int c,
           int d, int e, int f, 
           int g, int h, int i)
{
    //to store the value of determinant of the matrix formed by
    //the coefficients of the three lines
    long long int ans= (a*(e*i-f*h) - b*(d*i-f*g) + c*(d*h-e*g)); 
    
    if(ans==0){ //if value of determinant equals 0, they are concurrent
        return true;
    }
    
    else  //the value of determinant of the matrix is any value other than 0
    return false;
               
    
}

int main()
{
   int a, b, c;
   int d, e, f;
   int g, h, i;
   
   a=3, b=4, c=-13;
   d=2, e=-7, f=1;
   g=5, h=-1, i=-14;
   
   //to store the output of the function
   bool concurrent=check(a,b,c,d,e,f,g,h,i); 
   
   if(concurrent==true){ //if function returns true
       cout<<"The given three lines are concurrent"<<endl;
   }
   
   else  //if function returns false
       cout<<"The given three lines are not concurrent"<<endl;

    return 0;
}

Output

The given three lines are concurrent

Time Complexity : O(1) , as constant time is taken to check if the lines are concurrent or not.

Space Complexity : O(1) , as we didn't use any extra space.

Conclusion

We have discussed the idea of concurrent lines and offers a practical C++ method for determining if the three straight lines presented are concurrent or not. We used the method using straightforward mathematical ideas.

After reading this post, I hope you fully understood the concepts needed to solve the problem.

Updated on: 21-Aug-2023

115 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements