📜  给定圆弧的宽度和高度时的圆的半径

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

给定一个圆,其中给出了弧的宽度和高度。任务是借助圆弧的宽度和高度找到圆的半径。
例子:

Input: d = 4, h = 1 
Output: The radius of the circle is 2.5

Input: d = 14, h = 8
Output: The radius of the circle is 7.0625

方法

  • 设圆的半径为r
  • 设圆弧的高度和宽度为h & d
  • 现在,直径 DC 将弦 AB 一分为二,每半的长度为d/2
  • 直径也被弦分成两部分,弧内的部分h和剩余的2r-h
  • 现在从相交和弦定理,
    h*(2r-h) = (d/2)^2
    或者,2rh – h^2 = d^2/4
    所以,r = d^2/8h + h/2
  • 所以,圆的半径
    r = d^2/8h + h/2
C++
// C++ program to find
// radius of the circle
// when the width and height
// of an arc is given
 
#include 
using namespace std;
 
// Function to find the radius
void rad(double d, double h)
{
    cout << "The radius of the circle is "
        << ((d * d) / (8 * h) + h / 2)
        << endl;
}
 
// Driver code
int main()
{
    double d = 4, h = 1;
    rad(d, h);
    return 0;
}


Java
// Java program to find
// radius of the circle
// when the width and height
// of an arc is given
class GFG
{
 
// Function to find the radius
static void rad(double d, double h)
{
    System.out.println( "The radius of the circle is "
        + ((d * d) / (8 * h) + h / 2));
}
 
// Driver code
public static void main(String[] args)
{
    double d = 4, h = 1;
    rad(d, h);
}
}
 
/* This code contributed by PrinciRaj1992 */


Python3
# Python3 program to find
# radius of the circle
# when the width and height
# of an arc is given
 
# Function to find the radius
def rad(d, h):
    print("The radius of the circle is",
        ((d * d) / (8 * h) + h / 2))
 
# Driver code
d = 4; h = 1;
rad(d, h);
 
# This code is contributed by 29AjayKumar


C#
// C# program to find
// radius of the circle
// when the width and height
// of an arc is given
using System;
 
class GFG
{
 
// Function to find the radius
static void rad(double d, double h)
{
    Console.WriteLine( "The radius of the circle is "
        + ((d * d) / (8 * h) + h / 2));
}
 
// Driver code
public static void Main()
{
    double d = 4, h = 1;
    rad(d, h);
}
}
 
// This code is contributed by AnkitRai01


PHP


Javascript


输出:

The radius of the circle is 2.5

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