给定两个给定半径的圆,使圆彼此不接触,任务是找到圆心之间的距离与圆的两个直接公切线的交点的比值。
例子:
Input: r1 = 4, r2 = 6
Output: 2:3
Input: r1 = 22, r2 = 43
Output: 22:43
方法:
- 设圆的半径分别为r 1 & r 2 ,圆心分别为C 1 & C 2 。
- 设P为圆的两条直接公切线的交点, A 1 & A 2为切线与圆的接触点。
- 在三角形PC 1 A 1和三角形PC 2 A 2 中,
角C 1 A 1 P = 角C 2 A 2 P = 90 度{ 连接圆心和接触点的线与切线成 90 度角 },
同样,角度A 1 PC 1 = 角度A 2 PC 2
所以,角A 1 C 1 P = 角A 2 C 2 P
由于角度相同,三角形PC 1 A 1和PC 2 A 2是相似的。 - 所以,由于三角形的相似性,
C 1 P/C 2 P = C 1 A 1 /C 2 A 2 = r 1 /r 2
The ratio of the distance between the centres of the circles and the point of intersection of two direct common tangents to the circles = radius of the first circle : radius of the second circle
下面是上述方法的实现:
C++
// C++ program to find the ratio of the distance
// between the centers of the circles
// and the point of intersection of
// two direct common tangents to the circles
// which do not touch each other
#include
using namespace std;
// Function to find the GCD
int GCD(int a, int b)
{
return (b != 0 ? GCD(b, a % b) : a);
}
// Function to find the ratio
void ratiotang(int r1, int r2)
{
cout << "The ratio is "
<< r1 / GCD(r1, r2)
<< " : "
<< r2 / GCD(r1, r2)
<< endl;
}
// Driver code
int main()
{
int r1 = 4, r2 = 6;
ratiotang(r1, r2);
return 0;
}
Java
// Java program to find the ratio of the distance
// between the centers of the circles
// and the point of intersection of
// two direct common tangents to the circles
// which do not touch each other
class GFG {
// Function to find the GCD
static int GCD(int a, int b)
{
return (b != 0 ? GCD(b, a % b) : a);
}
// Function to find the ratio
static void ratiotang(int r1, int r2)
{
System.out.println("The ratio is "
+ r1 / GCD(r1, r2)
+ " : "
+ r2 / GCD(r1, r2));
}
// Driver code
public static void main(String args[])
{
int r1 = 4, r2 = 6;
ratiotang(r1, r2);
}
}
// This code has been contributed by 29AjayKumar
Python3
# Python 3 program to find the ratio
# of the distance between the centers
# of the circles and the point of intersection
# of two direct common tangents to the circles
# which do not touch each other
# Function to find the GCD
from math import gcd
# Function to find the ratio
def ratiotang(r1, r2):
print("The ratio is", int(r1 / gcd(r1, r2)), ":",
int(r2 / gcd(r1, r2)))
# Driver code
if __name__ == '__main__':
r1 = 4
r2 = 6
ratiotang(r1, r2)
# This code is contributed by
# Surendra_Gangwar
C#
// C# program to find the ratio of the distance
// between the centers of the circles
// and the point of intersection of
// two direct common tangents to the circles
// which do not touch each other
using System;
class GFG
{
// Function to find the GCD
static int GCD(int a, int b)
{
return (b != 0 ? GCD(b, a % b) : a);
}
// Function to find the ratio
static void ratiotang(int r1, int r2)
{
Console.WriteLine("The ratio is "
+ r1 / GCD(r1, r2)
+ " : "
+ r2 / GCD(r1, r2));
}
// Driver code
public static void Main(String[] args)
{
int r1 = 4, r2 = 6;
ratiotang(r1, r2);
}
}
// This code contributed by Rajput-Ji
PHP
Javascript
输出:
The ratio is 2 : 3