📌  相关文章
📜  如果给定半径和公共弦长,则两个相交圆的中心之间的距离

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

给定两个圆,具有给定的半径,它们彼此相交并具有共同的弦。给出了共同弦的长度。任务是找到两个圆心之间的距离。

例子:

Input:  r1 = 24, r2 = 37, x = 40
Output: 44

Input: r1 = 14, r2 = 7, x = 10
Output: 17

方法

  • 让公共弦长AB = x
  • 设圆心为O的圆的半径为OA = r2
  • P为中心的圆的半径是AP = r1
  • 从图中, OP垂直于AB
    AC = CB
    AC = x/2 (因为 AB = x)
  • 在三角形ACP 中
    AP^2 = PC^2+ AC^2 [根据毕达哥拉斯定理]
    r1^2 = PC^2 + (x/2)^2
    PC^2 = r1^2 – x^2/4
  • 考虑三角形ACO
    r2^2 = OC^2+ AC^2 [根据毕达哥拉斯定理]
    r2^2 = OC^2+ (x/2)^2
    OC^2 = r2^2 – x^2/4
  • 由图中OP=OC+PC
    OP = √( r1^2 – x^2/4 ) + √(r2^2 – x^2/4)

    下面是上述方法的实现:

    C++
    // C++ program to find
    // the distance between centers
    // of two intersecting circles
    // if the radii and common chord length is given
      
    #include 
    using namespace std;
      
    void distcenter(int r1, int r2, int x)
    {
        int z = sqrt((r1 * r1)
                     - (x / 2 * x / 2))
                + sqrt((r2 * r2)
                       - (x / 2 * x / 2));
      
        cout << "distance between the"
             << " centers is "
             << z << endl;
    }
      
    // Driver code
    int main()
    {
        int r1 = 24, r2 = 37, x = 40;
        distcenter(r1, r2, x);
        return 0;
    }


    Java
    // Java program to find
    // the distance between centers
    // of two intersecting circles
    // if the radii and common chord length is given
    import java.lang.Math; 
    import java.io.*;
      
    class GFG {
          
    static double distcenter(int r1, int r2, int x)
    {
        double z = (Math.sqrt((r1 * r1)
                    - (x / 2 * x / 2)))
                + (Math.sqrt((r2 * r2)
                    - (x / 2 * x / 2)));
      
        System.out.println ("distance between the" +
                            " centers is "+ (int)z );
        return 0;
    }
      
    // Driver code
    public static void main (String[] args) 
    {
        int r1 = 24, r2 = 37, x = 40;
        distcenter(r1, r2, x);
    }
    }
      
    // This code is contributed by jit_t.


    Python3
    # Python program to find
    # the distance between centers
    # of two intersecting circles
    # if the radii and common chord length is given
      
    def distcenter(r1, r2, x):
        z = (((r1 * r1) - (x / 2 * x / 2))**(1/2)) +\
        (((r2 * r2)- (x / 2 * x / 2))**(1/2));
      
        print("distance between thecenters is ",end="");
        print(int(z));
      
    # Driver code
    r1 = 24; r2 = 37; x = 40;
    distcenter(r1, r2, x);
      
    # This code has been contributed by 29AjayKumar


    C#
    // C# program to find
    // the distance between centers
    // of two intersecting circles
    // if the radii and common chord length is given
    using System;
      
    class GFG
    {
              
    static double distcenter(int r1, int r2, int x)
    {
        double z = (Math.Sqrt((r1 * r1)
                    - (x / 2 * x / 2)))
                + (Math.Sqrt((r2 * r2)
                    - (x / 2 * x / 2)));
      
        Console.WriteLine("distance between the" +
                            " centers is "+ (int)z );
        return 0;
    }
      
    // Driver code
    static public void Main ()
    {
        int r1 = 24, r2 = 37, x = 40;
        distcenter(r1, r2, x);
    }
    }
      
    // This code is contributed by jit_t


    输出:
    distance between the centers is 44
    

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