📌  相关文章
📜  两个不相交的圆之间的直接公切线的长度

📅  最后修改于: 2021-04-27 23:49:53             🧑  作者: Mango

给定半径的给定两个圆,它们的中心之间相距给定的距离,这样,圆就不会彼此接触。任务是找到圆之间的直接公切线的长度。
例子:

Input: r1 = 4, r2 = 6, d = 12 
Output: 11.8322

Input: r1 = 5, r2 = 9, d = 25
Output: 24.6779

方法

  • 令圆的半径分别为r1r2
  • 设中心之间的距离为d单位。
  • 画一条线平行于PQ
  • 角度OPQ = 90度
    角度O’QP = 90度
    {将圆心与接触点连接的线与切线成90度角}
  • 角度OPQ +角度O’QP = 180度
    OP ||二维码
  • 由于相对的边平行并且内角为90,因此OPQR为矩形。
  • 因此OP = QR = r1PQ = OR = d
  • 在三角形OO’R
    角ORO’= 90
    毕达哥拉斯定理
    OR ^ 2 + O’R ^ 2 =(OO’^ 2)
    OR ^ 2 +(r1-r2)^ 2 = d ^ 2
  • 因此, OR ^ 2 = d ^ 2-(r1-r2)^ 2
    OR =√{d ^ 2-(r1-r2)^ 2}
    length of direct common tangent = sqrt((distance between centers)^2 -(difference of radii)^2)

下面是上述方法的实现:

C++
// C++ program to find
// the length of the direct
// common tangent between two circles
// which donot touch each other
 
#include 
using namespace std;
 
// Function to find the length of the direct common tangent
void lengtang(double r1, double r2, double d)
{
    cout << "The length of the direct"
        <<" common tangent is "
        << sqrt(pow(d, 2) - pow((r1 - r2), 2))
        << endl;
}
 
// Driver code
int main()
{
    double r1 = 4, r2 = 6, d = 12;
    lengtang(r1, r2, d);
    return 0;
}


Java
// Java program to find
// the length of the direct
// common tangent between two circles
// which donot touch each other
class GFG
{
 
// Function to find the length of
// the direct common tangent
static void lengtang(double r1, double r2, double d)
{
    System.out.println("The length of the direct"
        +" common tangent is "
        +(Math.sqrt(Math.pow(d, 2) -
        Math.pow((r1 - r2), 2))));
}
 
// Driver code
public static void main(String[] args)
{
    double r1 = 4, r2 = 6, d = 12;
    lengtang(r1, r2, d);
}
}
 
/* This code contributed by PrinciRaj1992 */


Python3
# Python3 program to find
# the length of the direct
# common tangent between two circles
# which do not touch each other
import math
 
# Function to find the length
# of the direct common tangent
def lengtang(r1, r2, d):
    print("The length of the direct common tangent is",
        (((d ** 2) - ((r1 - r2) ** 2)) ** (1 / 2)));
 
# Driver code
r1 = 4; r2 = 6; d = 12;
lengtang(r1, r2, d);
 
# This code is contributed by 29AjayKumar


C#
// C# program to find
// the length of the direct
// common tangent between two circles
// which donot touch each other
using System;
 
class GFG
{
 
    // Function to find the length of
    // the direct common tangent
    static void lengtang(double r1, double r2, double d)
    {
        Console.WriteLine("The length of the direct"
            +" common tangent is "
            +(Math.Sqrt(Math.Pow(d, 2) -
            Math.Pow((r1 - r2), 2))));
    }
     
    // Driver code
    public static void Main()
    {
        double r1 = 4, r2 = 6, d = 12;
        lengtang(r1, r2, d);
    }
}
 
// This code is contributed by AnkitRai01


PHP


Javascript


输出:

The length of the direct common tangent is 11.8322