双星问题:
// 注意这题原点一定不会被包含在圆内,因为我们从实际意义出发考虑可以知道。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double pi = acos(-1); // 这个就是pi的实现方式 , 因为 acos(-1),在数学上就是等于 pi 的值 。
struct circle
{
LL x, y, r;
double a, b;
void input() { cin >> x >> y >> r; }
void cal_ab()
{ // 计算圆所占的极角序区间 [a, b] //计算的是这个圆所对应的角度范围
double mid = atan2(y, x), rad = asin(r / sqrt(x * x + y * y)) ;// atan2(y , x ) 表示的是点(x , y ) 跟 x 轴 形成的夹角。
a = mid - rad, b = mid + rad;
}
};
bool check_intersected(double a, double b, double c, double d)
{// 判断两个区间 [a, b], [c, d] 是否有交集
return c > a && a < b && d < b && d > a;
}
circle c1, c2;
int main()
{
c1.input(), c2.input();
c1.cal_ab(), c2.cal_ab();
if(c1.x * c1.x + c1.y * c1.y > c2.x * c2.x + c2.y * c2.y) swap(c1, c2); // 靠近原点的圆作为 c1
for(double dt : {0.0 , -2 * pi, 2 * pi } ) // dt 为什么需要这个遍历呢??????????????
{
double a = c1.a, b = c1.b, c = c2.a + dt, d = c2.b + dt;
if(check_intersected(a, b, c, d))
{
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}