📜  右风筝的外圆和内圆面积

📅  最后修改于: 2021-10-23 08:15:39             🧑  作者: Mango

给定两个正整数AB代表右风筝的边,任务是找到右风筝的外接圆和内圆的面积。

例子:

方法:有一些观察可以解决这个问题。请按照以下步骤解决此问题:

  • 这里, a = AB = ADb = BC = CD
  • 在风筝ABCD 中BD 的对角为90° ,因此对角可以计算为tan (A/2) = b/atan(C/2) = a/b
  • p为对角线AC的长度, q为对角线BD的长度。
  • 使用毕达哥拉斯定理可以轻松计算对角线AC 。因此p = (a 2 + b 2 ) ½
  • 由于对角线等于风筝外接圆的直径,外接圆的半径计算为R = (a 2 + b 2 ) ½ /2
  • 因此,外接圆的面积将是pi * R* R
  • 此外所有风筝都是切线四边形,因此内圆的半径可以通过r = 风筝面积/风筝的半周长来计算,即r = a*b/(a+b)。
  • 因此,内圆的面积将为pi*r*r。

下面是上述方法的实现:

C++
// C++ program for the above approach
 
#include 
using namespace std;
#define pi 3.14
 
// Function to calculate the area of
// circumcircle of right kite
double AreaOfCircumcircle(int a, int b)
{
    // Find the radius
    double radius = sqrt(a * a + b * b)
                    / 2;
    return pi * radius * radius;
}
 
// Function to calculate the area of
// incircle of right kite
double AreaOfIncircle(int a, int b)
{
    // Find the radius
    double radius = (a * b) / (a + b);
 
    return pi * radius * radius;
}
 
// Driver Code
int main()
{
    // Given Input
    int a, b;
    a = 10;
    b = 5;
 
    // Function Call
    double circumarea = AreaOfCircumcircle(
        a, b);
    cout << "Area of circumcircle of Right Kite is"
         << " " << circumarea << endl;
 
    // Function Call
    double inarea = AreaOfIncircle(
        a, b);
    cout << "Area of incircle of Right Kite is"
         << " " << inarea << endl;
 
    return 0;
}


Java
// Java program for the above approach
public class GFG {
    static double pi = 3.14;
 
    // Function to calculate the area of
    // circumcircle of right kite
    static double AreaOfCircumcircle(int a, int b)
    {
        // Find the radius
        double radius = Math.sqrt(a * a + b * b) / 2;
        return pi * radius * radius;
    }
 
    // Function to calculate the area of
    // incircle of right kite
    static double AreaOfIncircle(int a, int b)
    {
        // Find the radius
        double radius = (a * b) / (a + b);
 
        return pi * radius * radius;
    }
   
    // Driver code
    public static void main(String[] args)
    {
       
        // Given Input
        int a, b;
        a = 10;
        b = 5;
 
        // Function Call
        double circumarea = AreaOfCircumcircle(a, b);
        System.out.printf(
            "Area of circumcircle of Right Kite is %.3f\n",
            circumarea);
 
        // Function Call
        double inarea = AreaOfIncircle(a, b);
        System.out.printf(
            "Area of incircle of Right Kite is %.2f\n",
            inarea);
    }
}
 
// This code is contributed by abhinavjain194


Python3
# Python program for the above approach
# Function to calculate the area of
# circumcircle of right kite
import math
pi = 3.14
 
def AreaOfCircumcircle(a, b):
 
    # Find the radius
    radius = math.sqrt(a * a + b * b)/ 2
    return pi * radius * radius
 
 
# Function to calculate the area of
# incircle of right kite
def AreaOfIncircle( a,  b):
 
    # Find the radius
    radius = (a * b) // (a + b)
    return pi * (radius**2)
 
 
# Driver Code
# Given Input
a = 10
b = 5
 
# Function Call
circumarea = AreaOfCircumcircle(a, b)
print("Area of circumcircle of Right Kite is" ," " , format(circumarea,".3f"))
 
# Function Call
inarea = AreaOfIncircle(a, b)
print("Area of incircle of Right Kite is" ," " , format(inarea,".2f"))
 
# this code is contributed by shivanisinghss2110


C#
// C# program for the above approach
using System;
 
class GFG{
     
static double pi = 3.14;
 
// Function to calculate the area of
// circumcircle of right kite
static double AreaOfCircumcircle(int a, int b)
{
     
    // Find the radius
    double radius = Math.Sqrt(a * a + b * b) / 2;
    return pi * radius * radius;
}
 
// Function to calculate the area of
// incircle of right kite
static double AreaOfIncircle(int a, int b)
{
     
    // Find the radius
    double radius = (a * b) / (a + b);
 
    return pi * radius * radius;
}
 
// Driver code
public static void Main()
{
     
    // Given Input
    int a, b;
    a = 10;
    b = 5;
 
    // Function Call
    double circumarea = AreaOfCircumcircle(a, b);
    Console.WriteLine(
        "Area of circumcircle of Right Kite is " +
        circumarea);
 
    // Function Call
    double inarea = AreaOfIncircle(a, b);
    Console.WriteLine(
        "Area of incircle of Right Kite is " + inarea);
}
}
 
// This code is contributed by subhammahato348


Javascript


输出
Area of circumcircle of Right Kite is 98.125
Area of incircle of Right Kite is 28.26

时间复杂度:O(1)
辅助空间:O(1)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程