Comprobar si tres rectas son concurrentes o no

Dada una ecuación de tres líneas, 
a 1 x + b 1 y + c 1 = 0 
a 2 x + b 2 y + c 2 = 0 
a 3 x + b 3 y + c 3 = 0
La tarea es verificar si los tres dados las líneas son concurrentes o no. Se dice que tres rectas son concurrentes si pasan por un punto, es decir, se encuentran en un punto.
Ejemplos: 
 

Input : a1 = 2, b1 = -3, c1 = 5
        a2 = 3, b2 = 4, c2 = -7
        a3 = 9, b3 = -5, c3 = 8
Output : Yes

Input : a1 = 2, b1 = -3, c1 = 5
        a2 = 3, b2 = 4, c2 = -7
        a3 = 9, b3 = -5, c3 = 4
Output : No

Sea 
a 1 x + b 1 y + c 1 = 0 ………. (1) 
a 2 x + b 2 y + c 2 = 0 ………. (2) 
a 3 x + b 3 y + c 3 = 0 ………. (3)
Suponga que la ecuación (i) y (ii) se cruzan en (x 1 , y 1 ). Entonces (x 1 , y 1 ) satisfará ambas ecuaciones. 
Por lo tanto, resolviendo (i) y (ii) usando el método de multiplicación cruzada , obtenemos, 
(x 1 /b 1 c 2 – b 2 c 1) = (y 1 /c 1 a 2 – c 2 a 1 ) = (1/a 1 b 2 – a 2 b 1 )
Por lo tanto, 
x 1 = (b 1 c 2 – b 2 c 1 /a 1 b 2 – a 2 b 1 ) y 
y 1 = (c 1 a 2 – c 2 a 1 /a 1 b 2 – a 2 b 1), a 1 b 2 – a 2 b 1 != 0
Por lo tanto, las coordenadas requeridas del punto de intersección de las rectas (i) y (ii) son 
(b 1 c 2 – b 2 c 1 /a 1 b 2 – a 2 b 1 , c 1 a 2 – c 2 a 1 /a 1 b 2 – a 2 b 1 )
Para que tres de la línea sean concurrentes, (x 1 , y 1) debe satisfacer la ecuación (iii) también. 
Entonces, 
a 3 x + b 3 y + c 3 = 0 
=> a 3 (b 1 c 2 – b 2 c 1 /a 1 b 2 – a 2 b 1 ) + b 3 (c 1 a 2 – c 2 a 1 /a 1 b 2 – a 2 b 1 ) + c 3 = 0 
=> a 3 (b 1 c 2– b 2 c 1 ) + b 3 (c 1 a 2 – c 2 a 1 ) + c 3 (a 1 b 2 – a 2 b 1 ) = 0
Entonces, solo necesitamos verificar si la condición anterior se cumple o no.
A continuación se muestra la implementación de este enfoque: 
 

C++

// CPP Program to check if three straight
// line are concurrent or not
#include <bits/stdc++.h>
using namespace std;
 
// Return true if three line are concurrent,
// else false.
bool checkConcurrent(int a1, int b1, int c1,
                      int a2, int b2, int c2,
                      int a3, int b3, int c3)
{
    return (a3 * (b1 * c2 - b2 * c1) +
            b3 * (c1 * a2 - c2 * a1) + 
            c3 * (a1 * b2 - a2 * b1) == 0);
}
 
// Driven Program
int main()
{
    int a1 = 2, b1 = -3, c1 = 5;
    int a2 = 3, b2 = 4, c2 = -7;
    int a3 = 9, b3 = -5, c3 = 8;
 
    (checkConcurrent(a1, b1, c1, a2, b2, c2,
     a3, b3, c3) ? (cout << "Yes") : (cout << "No"));
    return 0;
}

Java

// Java Program to check if three straight
// line are concurrent or no
import java.io.*;
 
class GFG {
 
    // Return true if three line are concurrent,
    // else false.
    static boolean checkConcurrent(int a1, int b1,
                   int c1, int a2, int b2, int c2,
                           int a3, int b3, int c3)
    {
        return (a3 * (b1 * c2 - b2 * c1) +
                b3 * (c1 * a2 - c2 * a1) +
                c3 * (a1 * b2 - a2 * b1) == 0);
    }
     
    // Driven Program
    public static void main (String[] args)
    {
        int a1 = 2, b1 = -3, c1 = 5;
        int a2 = 3, b2 = 4, c2 = -7;
        int a3 = 9, b3 = -5, c3 = 8;
     
        if(checkConcurrent(a1, b1, c1, a2, b2,
                               c2, a3, b3, c3))
            System.out.println( "Yes");
        else
            System.out.println( "No");
    }
}
 
// This code is contributed by anuj_67.

Python 3

# Python3 Program to check if three straight
# line are concurrent or not
 
# Return true if three line are concurrent,
# else false.
def checkConcurrent(a1, b1, c1, a2, b2, c2,
                                 a3, b3, c3):
 
    return (a3 * (b1 * c2 - b2 * c1) +
            b3 * (c1 * a2 - c2 * a1) +
            c3 * (a1 * b2 - a2 * b1) == 0)
 
 
# Driven Program
a1 = 2
b1 = -3
c1 = 5
a2 = 3
b2 = 4
c2 = -7
a3 = 9
b3 = -5
c3 = 8
 
if(checkConcurrent(a1, b1, c1, a2, b2, c2,
                               a3, b3, c3)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by Smitha

C#

// C# Program to check if three straight
// line are concurrent or no
using System;
 
class GFG {
 
    // Return true if three line are concurrent,
    // else false.
    static bool checkConcurrent(int a1, int b1,
                int c1, int a2, int b2, int c2,
                        int a3, int b3, int c3)
    {
        return (a3 * (b1 * c2 - b2 * c1) +
                b3 * (c1 * a2 - c2 * a1) +
                c3 * (a1 * b2 - a2 * b1) == 0);
    }
     
    // Driven Program
    public static void Main ()
    {
        int a1 = 2, b1 = -3, c1 = 5;
        int a2 = 3, b2 = 4, c2 = -7;
        int a3 = 9, b3 = -5, c3 = 8;
     
        if(checkConcurrent(a1, b1, c1, a2, b2,
                            c2, a3, b3, c3))
            Console.WriteLine( "Yes");
        else
            Console.WriteLine( "No");
    }
}
 
// This code is contributed by anuj_67.

PHP

<?php
// PHP Program to check if three straight
// line are concurrent or not
 
// Return true if three line are
// concurrent, else false.
function checkConcurrent($a1, $b1, $c1,
                         $a2, $b2, $c2,
                         $a3, $b3, $c3)
{
    return ($a3 * ($b1 * $c2 - $b2 * $c1) +
            $b3 * ($c1 * $a2 - $c2 * $a1) +
            $c3 * ($a1 * $b2 - $a2 * $b1) == 0);
}  
 
    // Driver Code
    $a1 = 2; $b1 = -3; $c1 = 5;
    $a2 = 3; $b2 = 4; $c2 = -7;
    $a3 = 9; $b3 = -5; $c3 = 8;
 
    if(checkConcurrent($a1, $b1, $c1, $a2, $b2,
                           $c2, $a3, $b3, $c3))
        echo "Yes";
    else
        echo "No";
 
// This code is contributed by anuj_67.
?>

Javascript

<script>
 
// Javascript Program to check if three straight
// line are concurrent or not
 
// Return true if three line are concurrent,
// else false.
function checkConcurrent( a1,  b1,  c1,
                       a2,  b2,  c2,
                       a3,  b3,  c3)
{
    return (a3 * (b1 * c2 - b2 * c1) +
            b3 * (c1 * a2 - c2 * a1) + 
            c3 * (a1 * b2 - a2 * b1) == 0);
}
 
// Driven Program
a1 = 2, b1 = -3, c1 = 5;
a2 = 3, b2 = 4, c2 = -7;
a3 = 9, b3 = -5, c3 = 8;
(checkConcurrent(a1, b1, c1, a2, b2, c2,
 a3, b3, c3) ? (document.write( "Yes")) : (document.write( "No")));
 
</script>
Producción: 

Yes

 

Publicación traducida automáticamente

Artículo escrito por anuj0503 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *