ACM模版
判断线段与圆是否相交
typedef long long ll;
typedef struct
{
ll x, y;
} Point;
Point A, B, C, O;
ll r;
int segOnCircle(Point *p_1, Point *p_2)
{
ll a, b, c, dist_1, dist_2, angle_1, angle_2;
if (p_1->x == p_2->x)
{
a = 1, b = 0, c = -p_1->x;
}
else if (p_1->y == p_2->y)
{
a = 0, b = 1, c = -p_1->y;
}
else
{
a = p_1->y - p_2->y;
b = p_2->x - p_1->x;
c = p_1->x * p_2->y - p_1->y * p_2->x;
}
dist_1 = a * O.x + b * O.y + c;
dist_1 *= dist_1;
dist_2 = (a * a + b * b) * r * r;
if (dist_1 > dist_2)
{
return 0;
}
angle_1 = (O.x - p_1->x) * (p_2->x - p_1->x) + (O.y - p_1->y) * (p_2->y - p_1->y);
angle_2 = (O.x - p_2->x) * (p_1->x - p_2->x) + (O.y - p_2->y) * (p_1->y - p_2->y);
if (angle_1 > 0 && angle_2 > 0)
{
return 1;
}
return 0;
}