📜  使用半径和周长的三角形的内心和外心之间的距离

📅  最后修改于: 2021-04-22 01:43:41             🧑  作者: Mango

给定两个整数rR分别表示半径圆周半径的长度,任务是计算中心距和中心距之间的距离d

Inradius正三角形的inradius(R)(ABC)是(具有中心为L)的内切圆,其是将配合在三角形内的最大圆的半径。
外接半径:三角形的外接半径(R)是该三角形的外接圆的半径(以O为中心)。

例子:

方法:
可以使用几何学中的欧拉定理解决该问题,该定理指出,三角形的中心和外心之间的距离可以通过以下公式计算:

下面是上述方法的实现:

C++14
// C++14 program for the above approach
#include 
using namespace std;
 
// Function returns the required distance
double distance(int r, int R)
{
    double d = sqrt(pow(R, 2) -
                       (2 * r * R));
                             
    return d;
}
 
// Driver code
int main()
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
 
    cout << (round(distance(r, R) * 100.0) / 100.0);
}
 
// This code is contributed by sanjoy_62


Java
// Java program for the above approach
import java.util.*;
 
class GFG{
     
// Function returns the required distance
static double distance(int r,int R)
{
    double d = Math.sqrt(Math.pow(R, 2) -
                         (2 * r * R));
                          
    return d;
}
 
// Driver code
public static void main(String[] args)
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
 
    System.out.println(Math.round(
        distance(r, R) * 100.0) / 100.0);
}
}
 
// This code is contributed by offbeat


Python3
# Python3 program for the above approach
import math
 
# Function returns the required distance
def distance(r,R):
 
    d = math.sqrt( (R**2) - (2 * r * R))
     
    return d
 
# Driver Code
 
# Length of Inradius
r = 2
 
# Length of Circumradius
R = 5
 
print(round(distance(r,R),2))


C#
// C# program for the above approach
using System;
 
class GFG{
     
// Function returns the required distance
static double distance(int r, int R)
{
    double d = Math.Sqrt(Math.Pow(R, 2) -
                         (2 * r * R));
                         
    return d;
}
 
// Driver code
public static void Main(string[] args)
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
     
    Console.Write(Math.Round(
        distance(r, R) * 100.0) / 100.0);
}
}
 
// This code is contributed by rutvik_56


Javascript


输出:
2.24

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