#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
point(double A, double B) {
x = A, y = B;
}
point() = default;
};
struct line {
point point_A, point_B;
line(point A, point B) {
point_A = A, point_B = B;
}
line() = default;
};
struct Circle {
point O;
int r;
Circle(point A, int B) {
O = A, r = B;
}
Circle() = default;
};
double getDistance(const Circle& circle, const line& l) {
// 请在这里实现你的代码
double ox = circle.O.x, oy = circle.O.y;
double r = circle.r;
double x1 = l.point_A.x, y1 = l.point_A.y;
double x2 = l.point_B.x, y2 = l.point_B.y;
// 计算直线方程的参数 A, B, C
double A = y2 - y1;
double B = x1 - x2;
double C = x2 * y1 - x1 * y2;
// 计算圆心到直线的距离 d
double d = abs(A * ox + B * oy + C) / sqrt(A * A + B * B);
// 计算两点间的距离
if (d < r) {
return 2 * sqrt(r * r - d * d);
} else if (d == r) {
return 0.0;
}
// 根据题目备注,直线与圆不相离,所以不需要处理 d > r 的情况
return 0.0;
}
int main() {
double ox, oy, r;
double x1, y1, x2, y2;
cin >> ox >> oy >> r;
cin >> x1 >> y1 >> x2 >> y2;
point center(ox, oy);
Circle circle(center, (int)r);
point p1(x1, y1);
point p2(x2, y2);
line l(p1, p2);
double result = getDistance(circle, l);
cout << fixed << setprecision(6) << result << endl;
return 0;
}