📜  计算具有给定边长的循环四边形的面积

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

给定四个正整数ABCD表示循环四边形的边长,任务是找到循环四边形的面积。

例子:

方法:根据以下观察可以解决给定的问题:

  • 循环四边形是顶点都在一个圆上的四边形。圆称为外接圆或外接圆,顶点称为同环。

  • 在上图中, r是外接圆的半径, ABCD分别是边PQQRRSSP的长度。
  • 四边形的面积由Bretschneider 公式给出:

因此,想法是打印的值\sqrt(s - A)*(s - B)*(s - C)*(s - D)           作为给定四边形的合成面积。

下面是上述方法的实现:

C++
// C++ programm for the above approach
 
#include 
using namespace std;
 
// Function to find the area
// of cyclic quadrilateral
float calculateArea(float A, float B,
                    float C, float D)
{
    // Stores the value of
    // half of the perimeter
    float S = (A + B + C + D) / 2;
 
    // Stores area of cyclic quadrilteral
    float area = sqrt((S - A) * (S - B)
                      * (S - C) * (S - D));
 
    // Return the resultant area
    return area;
}
 
// Driver Code
int main()
{
    float A = 10;
    float B = 15;
    float C = 20;
    float D = 25;
    cout << calculateArea(A, B, C, D);
 
    return 0;
}


Java
// Java program for the above approach
import java.io.*;
 
class GFG{
     
// Function to find the area
// of cyclic quadrilateral
static float calculateArea(float A, float B,
                           float C, float D)
{
     
    // Stores the value of
    // half of the perimeter
    float S = (A + B + C + D) / 2;
 
    // Stores area of cyclic quadrilteral
    float area = (float)Math.sqrt((S - A) * (S - B) *
                                  (S - C) * (S - D));
 
    // Return the resultant area
    return area;
}
 
// Driver code
public static void main (String[] args)
{
    float A = 10;
    float B = 15;
    float C = 20;
    float D = 25;
     
    System.out.println(calculateArea(A, B, C, D));
 
}
}
 
// This code is contributed by Ankita saini


Python3
# Python3 programm for the above approach
from math import sqrt
 
# Function to find the area
# of cyclic quadrilateral
def calculateArea(A, B, C, D):
     
    # Stores the value of
    # half of the perimeter
    S = (A + B + C + D) // 2
 
    # Stores area of cyclic quadrilteral
    area = sqrt((S - A) * (S - B) *
                (S - C) * (S - D))
 
    # Return the resultant area
    return area
 
# Driver Code
if __name__ == '__main__':
     
    A = 10
    B = 15
    C = 20
    D = 25
     
    print(round(calculateArea(A, B, C, D), 3))
 
# This code is contributed by mohit kumar 29


C#
// C# program for the above approach
using System;
 
class GFG{
 
// Function to find the area
// of cyclic quadrilateral
static float calculateArea(float A, float B,
                           float C, float D)
{
     
    // Stores the value of
    // half of the perimeter
    float S = (A + B + C + D) / 2;
 
    // Stores area of cyclic quadrilteral
    float area = (float)Math.Sqrt((S - A) * (S - B) *
                                  (S - C) * (S - D));
 
    // Return the resultant area
    return area;
}
 
// Driver Code
static public void Main()
{
    float A = 10;
    float B = 15;
    float C = 20;
    float D = 25;
     
    Console.Write(calculateArea(A, B, C, D));
}
}
 
// This code is contributed by code_hunt


Javascript


输出:
273.861

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

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