给定两个具有给定半径的圆,它们的中心具有给定的距离,以使这些圆不会彼此接触。任务是找到圆之间的横向公共切线的长度。
例子:
Input: r1 = 4, r2 = 6, d = 12
Output: 6.63325
Input: r1 = 7, r2 = 9, d = 21
Output: 13.6015
方法:
- 令圆的半径分别为r1和r2 。
- 设中心之间的距离为d单位。
- 画一条与PQ平行的线O’R,
- 角度OPQ =角度RPQ = 90度
角度O’QP = 90度
{将圆心与接触点连接的线与切线成90度角} - 角RPQ +角O’QP = 180度
公关||奥奇 - 由于相对的边平行并且内角为90,因此O’PQR为矩形。
- O’Q = RP = r2和PQ = O’R
- 在三角形OO’R
角ORO’= 90度
根据毕达哥拉斯定理,
OR ^ 2 + O’R ^ 2 = OO’^ 2
O’R ^ 2 = OO’^ 2 – OR ^ 2
O’R ^ 2 = d ^ 2 –(r1 + r2)^ 2
O’R ^ 2 =√(d ^ 2 –(r1 + r2)^ 2)
C++
// C++ program to find the length
// of the transverse common tangent
// between two circles which
// do not touch each other
#include
using namespace std;
// Function to find the length
// of the transverse common tangent
void lengthOfTangent(double r1, double r2, double d)
{
cout << "The length of the transverse"
<< " common tangent is "
<< sqrt(pow(d, 2) - pow((r1 + r2), 2))
<< endl;
}
// Driver code
int main()
{
double r1 = 4, r2 = 6, d = 12;
lengthOfTangent(r1, r2, d);
return 0;
}
Java
// Java program to find the length
// of the transverse common tangent
// between two circles which
// do not touch each other
class GFG {
// Function to find the length
// of the transverse common tangent
static void lengthOfTangent(double r1,
double r2, double d)
{
System.out.println("The length of the transverse"
+ " 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;
lengthOfTangent(r1, r2, d);
}
}
// This code has been contributed by 29AjayKumar
Python3
# python 3 program to find the length
# of the transverse common tangent
# between two circles which
# do not touch each other
from math import sqrt, pow
# Function to find the length
# of the transverse common tangent
def lengthOfTangent(r1, r2, d):
print("The length of the transverse",
"common tangent is",
'{0:.6g}'.format(sqrt(pow(d, 2) -
pow((r1 + r2), 2))))
# Driver code
if __name__ == '__main__':
r1 = 4
r2 = 6
d = 12
lengthOfTangent(r1, r2, d)
# This code is contributed by
# Surendra_Gangwar
C#
// C# program to find the length
// of the transverse common tangent
// between two circles which
// do not touch each other
using System;
class GFG {
// Function to find the length
// of the transverse common tangent
static void lengthOfTangent(double r1,
double r2, double d)
{
Console.WriteLine("The length of the transverse"
+ " common tangent is "
+ Math.Sqrt(Math.Pow(d, 2)
- Math.Pow((r1 + r2), 2)));
}
// Driver code
static public void Main()
{
double r1 = 4, r2 = 6, d = 12;
lengthOfTangent(r1, r2, d);
}
}
// This code has been contributed by ajit.
PHP
Javascript
输出:
The length of the transverse common tangent is 6.63325