Área del Triángulo Mayor inscrito en un Hexágono

Dado que aquí hay un hexágono regular, de lado a , la tarea es encontrar el área del triángulo más grande que se puede inscribir en él.
Ejemplos: 
 

Input:  a = 6
Output: area = 46.7654

Input: a = 8
Output: area = 83.1384

Enfoque :
 

Está muy claro que el triángulo más grande que se puede inscribir dentro del hexágono es un triángulo equilátero. 
En el triángulo ACD
siguiendo el teorema de Pitágoras, 
(a/2)^2 + (b/2)^2 = a^2 
b^2/4 = 3a^2/4 
Entonces, b = a√3 
Por lo tanto, el área del triángulo, A = √3(a√3)^2/4= 3√3a^2/4

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

C++

// C++ Program to find the biggest triangle
// which can be inscribed within the hexagon
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the area
// of the triangle
float trianglearea(float a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // area of the triangle
    float area = (3 * sqrt(3) * pow(a, 2)) / 4;
 
    return area;
}
 
// Driver code
int main()
{
    float a = 6;
    cout << trianglearea(a) << endl;
 
    return 0;
}

Java

// Java Program to find the biggest triangle
// which can be inscribed within the hexagon
 
import java.io.*;
 
class GFG {
     
// Function to find the area
// of the triangle
static double trianglearea(double a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // area of the triangle
    double area = (3 * Math.sqrt(3) * Math.pow(a, 2)) / 4;
 
    return area;
}
 
    public static void main (String[] args) {
        double a = 6;
        System.out.println (trianglearea(a));
 
    }
//This Code is contributed by Sachin..
     
}

Python3

# Python3 Program to find the biggest triangle
# which can be inscribed within the hexagon
import math
 
# Function to find the area
# of the triangle
def trianglearea(a):
 
    # side cannot be negative
    if (a < 0):
        return -1;
 
    # area of the triangle
    area = (3 * math.sqrt(3) * math.pow(a, 2)) / 4;
 
    return area;
 
# Driver code
a = 6;
print(trianglearea(a))
 
# This code is contributed
# by Akanksha Rai

C#

// C# Program to find the biggest triangle
// which can be inscribed within the hexagon
 
using System;
 
class GFG {
     
// Function to find the area
// of the triangle
static double trianglearea(double a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // area of the triangle
    double area = (3 * Math.Sqrt(3) * Math.Pow(a, 2)) / 4;
 
    return Math.Round(area,4);
}
 
    public static void Main () {
        double a = 6;
        Console.WriteLine(trianglearea(a));
 
    }
        // This code is contributed by Ryuga
 
}

PHP

<?php
// PHP Program to find the biggest triangle
// which can be inscribed within the hexagon
 
// Function to find the area
// of the triangle
function trianglearea($a)
{
 
    // side cannot be negative
    if ($a < 0)
        return -1;
 
    // area of the triangle
    $area = (3 * sqrt(3) *
                 pow($a, 2)) / 4;
 
    return $area;
}
 
// Driver code
$a = 6;
echo trianglearea($a);
 
// This code is contributed
// by inder_verma
?>

Javascript

<script>
// javascript Program to find the biggest triangle
// which can be inscribed within the hexagon
 
   
// Function to find the area
// of the triangle
function trianglearea(a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // area of the triangle
    var area = (3 * Math.sqrt(3) * Math.pow(a, 2)) / 4;
 
    return area.toFixed(4);
}
 
var a = 6;
document.write(trianglearea(a));
 
// This code contributed by Princi Singh
 
</script>
Producción: 

46.7654

 

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

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