#include #include #include #include using namespace std; struct xyz{ double x, y, z; }; typedef complex xy; xy tang(xy p, double r) { double theta = arg(p); double l = abs(p); theta -= asin(r / l); double d = sqrt(l * l - r * r); return polar(d, theta); } double tangd(xy p, double r) { double theta = arg(p); double l = abs(p); theta -= asin(r / l); double d = sqrt(l * l - r * r); return d; } double distance (xyz &p1, xyz &p2) { return sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y) + (p2.z - p1.z) * (p2.z - p1.z)); } void main(void) { xyz a, b, c; double r; cin >> a.x >> a.y >> a.z; cin >> b.x >> b.y >> b.z; cin >> c.x >> c.y >> c.z; cin >> r; double ab = distance(a, b); // cout << ab << endl; double ac = distance(a, c); // cout << ac << endl; double bc = distance(b, c); // cout << bc << endl; double costheta = (ac * ac + ab * ab - bc * bc) / (2. * ac * ab); // cout << costheta << endl; double cx = ac * costheta; double h = sqrt(ac * ac - cx * cx); // cout << h << endl; if( h >= r || cx >= ab || cx <= 0. || ab <= 0.01) { printf("%.2f\n", ab); return; } xy ccenter(cx, h); xy tanleft = tang(ccenter, r); double leftd = tangd(ccenter, r); // cout << "ld" << leftd << endl; xy tanright = conj(xy(ab, 0) - tang(xy(ab - cx, h), r)); double rightd = tangd(xy(ab - cx, h), r); // cout << "rd" << rightd << endl; // cout << arg(tanleft - ccenter) << ":" << arg(tanright - ccenter) << endl; // cout << fabs(arg(tanleft - ccenter) - arg(tanright - ccenter)) << endl; double res = fabs(arg(tanleft - ccenter) * r - arg(tanright - ccenter) * r) + leftd + rightd; printf("%.2f\n", res); return; }