给定两个圆,其半径已给定,因此较小的完全位于较大的圆内,并且它们在一点上相互接触。我们必须找到连接圆心的线的垂直平分线的长度。
例子:
Input: r1 = 5, r2 = 3
Output: 9.79796
Input: r1 = 8, r2 = 4
Output: 15.4919
方法:
- 让这两个圆的中心在A和B 。垂直平分线PQ在C处平分线。
- 让大圆的半径 = r1
小圆的半径 = r2 - 所以, AB = r1-r2 ,
- 因此, AC = (r1-r2)/2
- 在图中,我们看到
PA = r1 - 在三角形ACP 中,
PC^2 + AC^2 = PA^2
PC^2 = PA^2 – AC^2
PC^2 = r1^2 – (r1-r2)^2/4 - 所以, PQ = 2*√(r1^2 – (r1-r2)^2/4)
Length of the perpendicular bisector = 2 * sqrt(r1^2 – (r1-r2)*(r1-r2)/4)
下面是上述方法的实现:
C++
// C++ program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
#include
using namespace std;
void lengperpbisect(double r1, double r2)
{
double z = 2 * sqrt((r1 * r1)
- ((r1 - r2)
* (r1 - r2) / 4));
cout << "The length of the "
<< "perpendicular bisector is "
<< z << endl;
}
// Driver code
int main()
{
double r1 = 5, r2 = 3;
lengperpbisect(r1, r2);
return 0;
}
Java
// Java program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
class GFG {
static void lengperpbisect(double r1, double r2)
{
double z = 2 * Math.sqrt((r1 * r1)
- ((r1 - r2)
* (r1 - r2) / 4));
System.out.println("The length of the "
+ "perpendicular bisector is "
+ z );
}
// Driver code
public static void main(String[] args)
{
double r1 = 5, r2 = 3;
lengperpbisect(r1, r2);
}
}
// This code has been contributed by 29AjayKumar
Python3
# Python program to find the Length
# of the perpendicular bisector
# of the line joining the centers
# of two circles in which one lies
# completely inside touching the
# bigger circle at one point
def lengperpbisect(r1, r2):
z = 2 * (((r1 * r1) - ((r1 - r2) * (r1 - r2) / 4))**(1/2));
print("The length of the perpendicular bisector is ", z);
# Driver code
r1 = 5; r2 = 3;
lengperpbisect(r1, r2);
# This code contributed by PrinciRaj1992
C#
// C# program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
using System;
class GFG
{
static void lengperpbisect(double r1, double r2)
{
double z = 2 * Math.Sqrt((r1 * r1)
- ((r1 - r2)
* (r1 - r2) / 4));
Console.WriteLine("The length of the "
+ "perpendicular bisector is "
+ z );
}
// Driver code
public static void Main()
{
double r1 = 5, r2 = 3;
lengperpbisect(r1, r2);
}
}
// This code has been contributed by anuj_67..
Javascript
输出:
The length of the perpendicular bisector is 9.79796
如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程和学生竞争性编程现场课程。