📜  使用边长的循环四边形的外接圆

📅  最后修改于: 2021-04-29 04:32:24             🧑  作者: Mango

给定表示循环四边形边长的整数A,B,CD ,任务是找到外圆半径,即给定循环四边形的外接圆半径。

例子:

方法:请按照以下步骤解决问题:

下面是上述方法的实现:

C++14
// C++ program to find circumradius of
// a cyclic quadrilateral using sides
#include 
using namespace std;
  
// Function to return the circumradius
// of a cyclic quadrilateral using sides
double Circumradius(int a, int b, int c, int d)
{
      
    // Find semiperimeter
    double s = (a + b + c + d) / 2.0;
  
    // Calculate the radius
    double radius = sqrt(((a * b) + (c * d)) *
                         ((a * c) + (b * d)) * 
                         ((a * d) + (b * c)) / 
                         ((s - a) * (s - b) * 
                          (s - c) * (s - d)));
  
    return radius / 4;
}
  
// Driver Code
int main()
{
    int A = 3;
    int B = 4;
    int C = 5;
    int D = 6;
  
    // Function call
    double ans = Circumradius(A, B, C, D);
  
    // Print the radius
    cout << setprecision(3) << ans;
  
    return 0;
}
  
// This code is contributed by mohit kumar 29


Java
// Java program to find circumradius of
// a cyclic quadrilateral using sides
import java.util.*;
  
class GFG{
  
// Function to return the circumradius
// of a cyclic quadrilateral using sides
static double Circumradius(int a, int b, 
                           int c, int d)
{
      
    // Find semiperimeter
    double s = (a + b + c + d) / 2.0;
  
    // Calculate the radius
    double radius = Math.sqrt(((a * b) + (c * d)) *
                              ((a * c) + (b * d)) * 
                              ((a * d) + (b * c)) / 
                              ((s - a) * (s - b) * 
                               (s - c) * (s - d)));
  
    return radius / 4;
}
  
// Driver Code
public static void main(String[] args)
{
    int A = 3;
    int B = 4;
    int C = 5;
    int D = 6;
  
    // Function call
    double ans = Circumradius(A, B, C, D);
  
    // Print the radius
    System.out.format("%.2f", ans);
}
}
  
// This code is contributed by 29AjayKumar


Python3
# Program to find Circumradius of
# a cyclic quadrilateral using sides
  
import math  
    
# Function to return the Circumradius
# of  a cyclic quadrilateral using sides
def Circumradius(a, b, c, d):
      
# Find semiperimeter
    s = (a + b + c + d) / 2
  
    # Calculate the radius
    radius = (1 / 4)*math.sqrt(((a * b)+(c * d))*
        ((a * c)+(b * d))*((a * d)+(b * c))
        /((s-a)*(s-b)*(s-c)*(s-d)))
      
    return radius  
    
# Driver Code
  
# Given sides
A = 3
B = 4
C = 5
D = 6
    
# Function Call  
ans = Circumradius(A, B, C, D)  
    
# Print the radius
print(round(ans, 2))


C#
// C# program to find circumradius of
// a cyclic quadrilateral using sides
using System;
  
class GFG{
  
// Function to return the circumradius
// of a cyclic quadrilateral using sides
static double Circumradius(int a, int b, 
                           int c, int d)
{
      
    // Find semiperimeter
    double s = (a + b + c + d) / 2.0;
  
    // Calculate the radius
    double radius = Math.Sqrt(((a * b) + (c * d)) *
                              ((a * c) + (b * d)) * 
                              ((a * d) + (b * c)) / 
                              ((s - a) * (s - b) * 
                               (s - c) * (s - d)));
  
    return radius / 4;
}
  
// Driver Code
public static void Main(String[] args)
{
    int A = 3;
    int B = 4;
    int C = 5;
    int D = 6;
  
    // Function call
    double ans = Circumradius(A, B, C, D);
  
    // Print the radius
    Console.Write("{0:F2}", ans);
}
}
  
// This code is contributed by 29AjayKumar


输出:
3.29

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