📜  两个相交圆的直接公切线长度

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

给定半径给定的两个圆,它们的中心相距给定的距离,使得这些圆在两点相交。任务是找到圆之间的直接公切线的长度。
例子:

Input: r1 = 4, r2 = 6, d = 3  
Output: 2.23607

Input: r1 = 14, r2 = 43, d = 35
Output: 19.5959

方法

  • 设圆的半径分别为r1r2

  • 让中心之间的距离为d 个单位。
  • 画一条线 OR 平行于 PQ
  • 角度 OPQ = 90 度
    角度 O’QP = 90 度
    { 连接圆心和接触点的线与切线成 90 度角 }
  • 角度 OPQ + 角度 O’QP = 180 度
    操作||二维码
  • 由于对边平行且内角为90°,所以OPQR是一个矩形。
  • 所以OP = QR = r1 和 PQ = OR = d
  • 三角形 OO’R
    角度 ORO’ = 90
    根据毕达哥拉斯定理
    OR^2 + O’R^2 = (OO’^2)
    或^2 + (r1-r2)^2 = d^2
  • 所以, OR^2= d^2-(r1-r2)^2
    OR = √{d^2-(r1-r2)^2}
    Length of the direct common tangent = sqrt((distancebetweencenters)^2 - (difference of radii)^2)

下面是上述方法的实现:

C++
// C++ program to find
// the length of the direct
// common tangent between two circles
// which intersect 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 = 3;
    lengtang(r1, r2, d);
    return 0;
}


Java
// Java program to find
// the length of the direct
// common tangent between two circles
// which intersect 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 = 3;
        lengtang(r1, r2, d);
    }
}
 
/* This code contributed by PrinciRaj1992 */


Python3
# Python program to find
# the length of the direct
# common tangent between two circles
# which intersect each other
  
# 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 = 3;
lengtang(r1, r2, d);
 
# This code has been contributed by 29AjayKumar


C#
// C# program to find
// the length of the direct
// common tangent between two circles
// which intersect 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(String[] args)
    {
        double r1 = 4, r2 = 6, d = 3;
        lengtang(r1, r2, d);
    }
}
 
/* This code contributed by PrinciRaj1992 */


PHP


Javascript


输出:
The length of the direct common tangent is 2.23607

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