Area del circulo inscrito dentro del rombo

Dado un rombo de diagonales a y b , que contiene una circunferencia inscrita. La tarea es encontrar el área de ese círculo en términos de a y b.
Ejemplos: 
 

Input: l = 5, b = 6
Output: 11.582

Input: l = 8, b = 10
Output: 30.6341

Enfoque: A partir de la figura, vemos que el radio del círculo inscrito es también una altura h=OH del triángulo rectángulo AOB . Para encontrarlo, usamos ecuaciones para el área del triángulo:
 

Área AOB = 1/2 * (a/2) * (b/2) = ab/8 = 12 canales

 donde c = AB , es decir, una hipotenusa. Asi que, 

r = h = ab/4c = ab/4√(a^2/4 + b^2/4) = ab/2√(a^2+b^2)

y por lo tanto el area del circulo es
 

A = Π * r^2 = Π a^2 b^2 /4(a2 + b2)

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

C++

// C++ Program to find the area of the circle
// which can be inscribed within the rhombus
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the area
// of the inscribed circle
float circlearea(float a, float b)
{
 
    // the diagonals cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the circle
    float A = (3.14 * pow(a, 2) * pow(b, 2))
            / (4 * (pow(a, 2) + pow(b, 2)));
    return A;
}
 
// Driver code
int main()
{
    float a = 8, b = 10;
    cout << circlearea(a, b) << endl;
 
    return 0;
}

Java

// Java Program to find the area of the circle
// which can be inscribed within the rhombus
 
public class GFG {
     
    // Function to find the area
    // of the inscribed circle
    public static float circlearea(double a, double b)
    {
        // the diagonals cannot be negative
        if (a < 0 || b < 0)
            return -1 ;
         
        //area of the circle
        float A = (float) ((3.14 * Math.pow(a, 2) * Math.pow(b, 2))
                        / (4 * (Math.pow(a, 2) + Math.pow(b, 2)))) ;
         
        return A ;
    }
 
    // Driver code
    public static void main(String[] args) {
        float a = 8, b = 10 ;
         
        System.out.println(circlearea(a, b));
 
    }
// This code is contributed by ANKITRAI1
}

Python 3

# Python 3 Program to find the area of the circle
# which can be inscribed within the rhombus
 
 
# Function to find the area
# of the inscribed circle
def circlearea(a, b):
 
    # the diagonals cannot be negative
    if (a < 0 or b < 0):
        return -1
 
    # area of the circle
    A = ((3.14 * pow(a, 2) * pow(b, 2))/
        (4 * (pow(a, 2) + pow(b, 2))))
    return A
 
# Driver code
if __name__ == "__main__":
    a = 8
    b = 10
    print( circlearea(a, b))
 
# This code is contributed by ChitraNayal

C#

// C# Program to find the area of the circle
// which can be inscribed within the rhombus
using System;
 
public class GFG {
     
    // Function to find the area
    // of the inscribed circle
    public static float circlearea(double a, double b)
    {
        // the diagonals cannot be negative
        if (a < 0 || b < 0)
            return -1 ;
         
        //area of the circle
        float A = (float) ((3.14 * Math.Pow(a, 2) * Math.Pow(b, 2))
                        / (4 * (Math.Pow(a, 2) + Math.Pow(b, 2)))) ;
         
        return A ;
    }
 
    // Driver code
    public static void Main() {
        float a = 8, b = 10 ;
         
        Console.WriteLine(circlearea(a, b));
 
    }
// This code is contributed by inder_verma..
}

PHP

<?php
// PHP Program to find the area
// of the circle which can be
// inscribed within the rhombus
 
// Function to find the area
// of the inscribed circle
function circlearea($a, $b)
{
 
    // the diagonals cannot be negative
    if ($a < 0 || $b < 0)
        return -1;
 
    // area of the circle
    $A = (3.14 * pow($a, 2) * pow($b, 2)) /
           (4 * (pow($a, 2) + pow($b, 2)));
    return $A;
}
 
// Driver code
$a = 8; $b = 10;
echo circlearea($a, $b);
 
// This code is contributed by anuj_67
?>

Javascript

<script>
 
// javascript Program to find the area of the circle
// which can be inscribed within the rhombus
 
     
// Function to find the area
// of the inscribed circle
function circlearea(a , b)
{
    // the diagonals cannot be negative
    if (a < 0 || b < 0)
        return -1 ;
     
    //area of the circle
    var A =  ((3.14 * Math.pow(a, 2) * Math.pow(b, 2))
                    / (4 * (Math.pow(a, 2) + Math.pow(b, 2)))) ;
     
    return A ;
}
 
// Driver code
 
var a = 8, b = 10 ;
 
document.write(circlearea(a, b).toFixed(4));
 
 
// This code is contributed by Amit Katiyar
 
</script>
Producción: 

30.6341

 

Complejidad de tiempo: O(log a ) + O(log b ), donde log n es el tiempo requerido por la función pow
Espacio auxiliar: O(1), ya que no se requiere espacio adicional

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 *