在几何学中,笛卡尔定理指出,对于每四个相互相切的圆,圆的半径满足某个二次方程。可以构造与三个给定的相互相切的圆相切的第四个圆。
笛卡尔圆定理帮助我们在有4 个正整数半径为r1 、 r2 、 r3和r4的圆时找到圆的半径,如下图所示。它找到由半径为r1 、 r2 、 r3的三个圆形成的圆的半径r4 ,如下图所示。
(请注意,下图中的圆圈彼此相切。)
例子:
Input: r1 = 1, r2 = 1, r3 = 1
Output: 0.154701
Input: r1 =23, r2 = 46, r3 = 69
Output: 6.000000
该定理说,这些圆的半径或“曲率”的倒数
satisfies the following relation:
一个圆可以被其余三个圆包围,如图所示,在这种情况下,相应的曲率这里被认为是否定的,并且上述关系仍然成立。
如果已知,可以求解 k4,
在求解上述方程时,我们得到第四个圆的半径。求第四个圆的半径的公式是:
因此,如果 r1、r2 和 r3 已知,则可以使用上述公式轻松计算 r4。
下面是上述方法的实现:
CPP
// C++ implementation of the
// above formulae
#include
using namespace std;
// Function to find the fourth circle's
// when three radius are given
double findRadius(double r1, double r2, double r3)
{
double r4 = (r1 * r2 * r3)
/ (r1 * r2 + r2 * r3
+ r1 * r3 + 2.0 * sqrt(r1 * r2 * r3 * (r1 + r2 + r3)));
return r4;
}
// Driver code
int main()
{
// Radius of three circles
double r1 = 1;
double r2 = 1;
double r3 = 1;
// Calculation of r4 using formula given above
double r4 = findRadius(r1, r2, r3);
cout << "The radius of fourth circle: " << r4;
return 0;
}
Java
/*package whatever //do not write package name here */
// Java implementation of the
// above formulae
import java.io.*;
class GFG
{
// Function to find the fourth circle's
// when three radius are given
static double findRadius(double r1, double r2, double r3)
{
double r4 = (r1 * r2 * r3)
/ (r1 * r2 + r2 * r3
+ r1 * r3 + 2.0 * Math.sqrt(r1 * r2 * r3 * (r1 + r2 + r3)));
return r4;
}
// Driver code
public static void main (String[] args)
{
// Radius of three circles
double r1 = 1;
double r2 = 1;
double r3 = 1;
// Calculation of r4 using formula given above
double r4 = findRadius(r1, r2, r3);
System.out.println("The radius of fourth circle: " + r4);
}
}
// This code is contributed by CoderSaty.
Python3
# Python 3 implementation of the
# above formulae
from math import sqrt
# Function to find the fourth circle's
# when three radius are given
def findRadius(r1, r2, r3):
r4 = (r1 * r2 * r3) / (r1 * r2 + r2 * r3 + r1 * r3 + 2.0 * sqrt(r1 * r2 * r3 * (r1 + r2 + r3)))
return r4
# Driver code
if __name__ == '__main__':
# Radius of three circles
r1 = 1
r2 = 1
r3 = 1
# Calculation of r4 using formula given above
r4 = findRadius(r1, r2, r3)
print("The radius of fourth circle:",r4)
# This code is contributed by SURENDRA_GANGWAR.
C#
// C# implementation of the
// above formulae
using System;
class GFG
{
// Function to find the fourth circle's
// when three radius are given
static double findRadius(double r1, double r2, double r3)
{
double r4 = (r1 * r2 * r3)
/ (r1 * r2 + r2 * r3
+ r1 * r3 + 2.0 * Math.Sqrt(r1 * r2 * r3 * (r1 + r2 + r3)));
return r4;
}
// Driver code
public static void Main (String[] args)
{
// Radius of three circles
double r1 = 1;
double r2 = 1;
double r3 = 1;
// Calculation of r4 using formula given above
double r4 = Math.Round(findRadius(r1, r2, r3),6);
Console.Write("The radius of fourth circle: " + r4);
}
}
// This code is contributed by shivanisinghss2110
Javascript
输出:
The radius of fourth circle: 0.154701
如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程和学生竞争性编程现场课程。