Distancia entre el ortocentro y el circuncentro de un triángulo rectángulo

Dados tres pares de números enteros A(x, y) , B(x, y) y C(x, y) , que representan las coordenadas de un triángulo rectángulo , la tarea es encontrar la distancia entre el ortocentro y el circuncentro .

Ejemplos:

Entrada: A = {0, 0}, B = {5, 0}, C = {0, 12}
Salida: 6.5
Explicación:
El triángulo ABC forma un ángulo recto en el punto A. Por lo tanto, el ortocentro se encuentra en el punto A que es (0, 0).
La coordenada del circuncentro es (2.5, 6).
Por tanto, la distancia entre el ortocentro y el circuncentro es 6,5.

Entrada: A = {0, 0}, B = {6, 0}, C = {0, 8}
Salida: 5
Explicación:
El triángulo ABC forma un ángulo recto en el punto A. Por lo tanto, el ortocentro se encuentra en el punto A que es (0, 0).
La coordenada del circuncentro es (3, 4).
Por lo tanto, la distancia entre el ortocentro y el circuncentro es 5.

Enfoque: La idea es encontrar las coordenadas del ortocentro y el circuncentro del triángulo dado en base a las siguientes observaciones:
 

El ortocentro es un punto donde se encuentran tres alturas. En un triángulo rectángulo, el ortocentro es el vértice que está situado en el vértice del ángulo recto .
El circuncentro es el punto donde se encuentra la mediatriz del triángulo. En un triángulo rectángulo, el circuncentro se encuentra en el centro de la hipotenusa .

Siga los pasos a continuación para resolver el problema: 
 

  • Encuentra el más largo de los tres lados del triángulo rectángulo, es decir, la hipotenusa.
  • Encuentre el centro de la hipotenusa y póngalo como el circuncentro .
  • Encuentra el vértice opuesto al lado más largo y configúralo como el ortocentro .
  • Calcula la distancia entre ellos e imprímelo como resultado.

A continuación se muestra la implementación del enfoque anterior: 

C++

// C++ program for the above approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to calculate Euclidean
// distance between the points p1 and p2
double distance(pair<double, double> p1,
                pair<double, double> p2)
{
    // Stores x coordinates of both points
    double x1 = p1.first, x2 = p2.first;
 
    // Stores y coordinates of both points
    double y1 = p1.second, y2 = p2.second;
 
    // Return the Euclid distance
    // using distance formula
    return sqrt(pow(x2 - x1, 2)
                + pow(y2 - y1, 2) * 1.0);
}
 
// Function to find orthocenter of
// the right angled triangle
pair<double, double>
find_orthocenter(pair<double, double> A,
                 pair<double, double> B,
                 pair<double, double> C)
{
    // Find the length of the three sides
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Orthocenter will be the vertex
    // opposite to the largest side
    if (AB > BC && AB > CA)
        return C;
    if (BC > AB && BC > CA)
        return A;
    return B;
}
 
// Function to find the circumcenter
// of right angle triangle
pair<double, double>
find_circumcenter(pair<double, double> A,
                  pair<double, double> B,
                  pair<double, double> C)
{
    // Circumcenter will be located
    // at center of hypotenuse
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Find the hypotenuse and then
    // find middle point of hypotenuse
 
    // If AB is the hypotenuse
    if (AB > BC && AB > CA)
        return { (A.first + B.first) / 2,
                 (A.second + B.second) / 2 };
 
    // If BC is the hypotenuse
    if (BC > AB && BC > CA)
        return { (B.first + C.first) / 2,
                 (B.second + C.second) / 2 };
 
    // If AC is the hypotenuse
    return { (C.first + A.first) / 2,
             (C.second + A.second) / 2 };
}
 
// Function to find distance between
// orthocenter and circumcenter
void findDistance(pair<double, double> A,
                  pair<double, double> B,
                  pair<double, double> C)
{
 
    // Find circumcenter
    pair<double, double> circumcenter
        = find_circumcenter(A, B, C);
 
    // Find orthocenter
    pair<double, double> orthocenter
        = find_orthocenter(A, B, C);
 
    // Find the distance between the
    // orthocenter and circumcenter
    double distance_between
        = distance(circumcenter,
                   orthocenter);
 
    // Print distance between orthocenter
    // and circumcenter
    cout << distance_between << endl;
}
 
// Driver Code
int main()
{
    pair<double, double> A, B, C;
 
    // Given coordinates A, B, and C
    A = { 0.0, 0.0 };
    B = { 6.0, 0.0 };
    C = { 0.0, 8.0 };
 
    // Function Call
    findDistance(A, B, C);
 
    return 0;
}

Java

// Java program for the above approach
import java.util.*;
 
class GFG{
  static class pair
  {
    double first, second;
    public pair(double first, double second) 
    {
      this.first = first;
      this.second = second;
    }   
  }
 
  // Function to calculate Euclidean
  // distance between the points p1 and p2
  static double distance(pair p1,
                         pair p2)
  {
 
    // Stores x coordinates of both points
    double x1 = p1.first, x2 = p2.first;
 
    // Stores y coordinates of both points
    double y1 = p1.second, y2 = p2.second;
 
    // Return the Euclid distance
    // using distance formula
    return Math.sqrt(Math.pow(x2 - x1, 2)
                     + Math.pow(y2 - y1, 2) * 1.0);
  }
 
  // Function to find orthocenter of
  // the right angled triangle
  static pair
    find_orthocenter(pair A,
                     pair B,
                     pair C)
  {
 
    // Find the length of the three sides
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Orthocenter will be the vertex
    // opposite to the largest side
    if (AB > BC && AB > CA)
      return C;
    if (BC > AB && BC > CA)
      return A;
    return B;
  }
 
  // Function to find the circumcenter
  // of right angle triangle
  static pair
    find_circumcenter(pair A,
                      pair B,
                      pair C)
  {
 
    // Circumcenter will be located
    // at center of hypotenuse
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Find the hypotenuse and then
    // find middle point of hypotenuse
 
    // If AB is the hypotenuse
    if (AB > BC && AB > CA)
      return new pair((A.first + B.first) / 2,
                      (A.second + B.second) / 2 );
 
    // If BC is the hypotenuse
    if (BC > AB && BC > CA)
      return new pair((B.first + C.first) / 2,
                      (B.second + C.second) / 2 );
 
    // If AC is the hypotenuse
    return new pair( (C.first + A.first) / 2,
                    (C.second + A.second) / 2 );
  }
 
  // Function to find distance between
  // orthocenter and circumcenter
  static void findDistance(pair A,
                           pair B,
                           pair C)
  {
 
    // Find circumcenter
    pair circumcenter
      = find_circumcenter(A, B, C);
 
    // Find orthocenter
    pair orthocenter
      = find_orthocenter(A, B, C);
 
    // Find the distance between the
    // orthocenter and circumcenter
    double distance_between
      = distance(circumcenter,
                 orthocenter);
 
    // Print distance between orthocenter
    // and circumcenter
    System.out.print(distance_between +"\n");
  }
 
  // Driver Code
  public static void main(String[] args)
  {
    pair A, B, C;
 
    // Given coordinates A, B, and C
    A = new pair( 0.0, 0.0 );
    B = new pair(6.0, 0.0 );
    C = new pair(0.0, 8.0 );
 
    // Function Call
    findDistance(A, B, C);
  }
}
 
// This code is contributed by shikhasingrajput

Python3

# Python3 program for the above approach
import math
 
# Function to calculate Euclidean
# distance between the points p1 and p2
def distance(p1, p2) :
 
    # Stores x coordinates of both points
    x1, x2 = p1[0], p2[0]
  
    # Stores y coordinates of both points
    y1, y2 = p1[1], p2[1]
  
    # Return the Euclid distance
    # using distance formula
    return int(math.sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)))
     
# Function to find orthocenter of
# the right angled triangle
def find_orthocenter(A, B, C) :
 
    # Find the length of the three sides
    AB = distance(A, B)
    BC = distance(B, C)
    CA = distance(C, A)
  
    # Orthocenter will be the vertex
    # opposite to the largest side
    if (AB > BC and AB > CA) :
        return C
    if (BC > AB and BC > CA) :
        return A
    return B
     
# Function to find the circumcenter
# of right angle triangle
def find_circumcenter(A, B, C) :
 
    # Circumcenter will be located
    # at center of hypotenuse
    AB = distance(A, B)
    BC = distance(B, C)
    CA = distance(C, A)
  
    # Find the hypotenuse and then
    # find middle point of hypotenuse
  
    # If AB is the hypotenuse
    if (AB > BC and AB > CA) :
        return ((A[0] + B[0]) // 2, (A[1] + B[1]) // 2)
  
    # If BC is the hypotenuse
    if (BC > AB and BC > CA) :
        return ((B[0] + C[0]) // 2, (B[1] + C[1]) // 2)
  
    # If AC is the hypotenuse
    return ((C[0] + A[0]) // 2, (C[1] + A[1]) // 2)
     
# Function to find distance between
# orthocenter and circumcenter
def findDistance(A, B, C) :
  
    # Find circumcenter
    circumcenter = find_circumcenter(A, B, C)
  
    # Find orthocenter
    orthocenter = find_orthocenter(A, B, C)
  
    # Find the distance between the
    # orthocenter and circumcenter
    distance_between = distance(circumcenter, orthocenter)
  
    # Print distance between orthocenter
    # and circumcenter
    print(distance_between)
     
# Given coordinates A, B, and C
A = [ 0, 0 ]
B = [ 6, 0 ]
C = [ 0, 8 ]
 
# Function Call
findDistance(A, B, C)
 
# This code is contributed by divyesh072019.

C#

// C# program for the above approach
using System;
 
class GFG{
  public class pair
  {
    public double first, second;
    public pair(double first, double second) 
    {
      this.first = first;
      this.second = second;
    }   
  }
 
  // Function to calculate Euclidean
  // distance between the points p1 and p2
  static double distance(pair p1,
                         pair p2)
  {
 
    // Stores x coordinates of both points
    double x1 = p1.first, x2 = p2.first;
 
    // Stores y coordinates of both points
    double y1 = p1.second, y2 = p2.second;
 
    // Return the Euclid distance
    // using distance formula
    return Math.Sqrt(Math.Pow(x2 - x1, 2)
                     + Math.Pow(y2 - y1, 2) * 1.0);
  }
 
  // Function to find orthocenter of
  // the right angled triangle
  static pair
    find_orthocenter(pair A,
                     pair B,
                     pair C)
  {
 
    // Find the length of the three sides
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Orthocenter will be the vertex
    // opposite to the largest side
    if (AB > BC && AB > CA)
      return C;
    if (BC > AB && BC > CA)
      return A;
    return B;
  }
 
  // Function to find the circumcenter
  // of right angle triangle
  static pair
    find_circumcenter(pair A,
                      pair B,
                      pair C)
  {
 
    // Circumcenter will be located
    // at center of hypotenuse
    double AB = distance(A, B);
    double BC = distance(B, C);
    double CA = distance(C, A);
 
    // Find the hypotenuse and then
    // find middle point of hypotenuse
 
    // If AB is the hypotenuse
    if (AB > BC && AB > CA)
      return new pair((A.first + B.first) / 2,
                      (A.second + B.second) / 2 );
 
    // If BC is the hypotenuse
    if (BC > AB && BC > CA)
      return new pair((B.first + C.first) / 2,
                      (B.second + C.second) / 2 );
 
    // If AC is the hypotenuse
    return new pair( (C.first + A.first) / 2,
                    (C.second + A.second) / 2 );
  }
 
  // Function to find distance between
  // orthocenter and circumcenter
  static void findDistance(pair A,
                           pair B,
                           pair C)
  {
 
    // Find circumcenter
    pair circumcenter
      = find_circumcenter(A, B, C);
 
    // Find orthocenter
    pair orthocenter
      = find_orthocenter(A, B, C);
 
    // Find the distance between the
    // orthocenter and circumcenter
    double distance_between
      = distance(circumcenter,
                 orthocenter);
 
    // Print distance between orthocenter
    // and circumcenter
    Console.Write(distance_between +"\n");
  }
 
  // Driver Code
  public static void Main(String[] args)
  {
    pair A, B, C;
 
    // Given coordinates A, B, and C
    A = new pair( 0.0, 0.0 );
    B = new pair(6.0, 0.0 );
    C = new pair(0.0, 8.0 );
 
    // Function Call
    findDistance(A, B, C);
  }
}
 
// This code is contributed by 29AjayKumar

Javascript

<script>
// Javascript implementation for the above approach
 
// Function to calculate Euclidean
// distance between the points p1 and p2
function distance( p1, p2)
{
    // Stores x coordinates of both points
    var x1 = p1[0], x2 = p2[0];
  
    // Stores y coordinates of both points
    var y1 = p1[1], y2 = p2[1];
  
    // Return the Euclid distance
    // using distance formula
    return Math.sqrt(Math.pow(x2 - x1, 2)
                + Math.pow(y2 - y1, 2) * 1.0);
}
  
// Function to find orthocenter of
// the right angled triangle
function find_orthocenter( A, B, C)
{
    // Find the length of the three sides
    var AB = distance(A, B);
    var BC = distance(B, C);
    var CA = distance(C, A);
  
    // Orthocenter will be the vertex
    // opposite to the largest side
    if (AB > BC && AB > CA)
        return C;
    if (BC > AB && BC > CA)
        return A;
    return B;
}
  
// Function to find the circumcenter
// of right angle triangle
function find_circumcenter( A, B, C)
{
    // Circumcenter will be located
    // at center of hypotenuse
    var AB = distance(A, B);
    var BC = distance(B, C);
    var CA = distance(C, A);
  
    // Find the hypotenuse and then
    // find middle point of hypotenuse
  
    // If AB is the hypotenuse
    if (AB > BC && AB > CA)
        return [ Math.floor((A[0] + B[0]) / 2),
                 Math.floor((A[1] + B[1]) / 2) ];
  
    // If BC is the hypotenuse
    if (BC > AB && BC > CA)
        return [ Math.floor((B[0] + C[0]) / 2),
                 Math.floor((B[1] + C[1]) / 2) ];
  
    // If AC is the hypotenuse
    return [ Math.floor((C[0] + A[0]) / 2),
             Math.floor((C[1] + A[1]) / 2) ];
}
  
// Function to find distance between
// orthocenter and circumcenter
function findDistance( A, B, C)
{
  
    // Find circumcenter
     circumcenter = find_circumcenter(A, B, C);
  
    // Find orthocenter
     orthocenter = find_orthocenter(A, B, C);
  
    // Find the distance between the
    // orthocenter and circumcenter
    var distance_between
        = distance(circumcenter,
                   orthocenter);
  
    // Print distance between orthocenter
    // and circumcenter
    document.write(distance_between+"<br>");
}
  
// Driver Code
var A, B, C;
  
// Given coordinates A, B, and C
A = [ 0, 0 ];
B = [ 6, 0 ];
C = [ 0, 8 ];
 
// Function Call
findDistance(A, B, C);
 
// This code is contributed by Shubham Singh
</script>
Producción: 

5

 

Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por AyushMalik 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 *