SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | #include <fstream> | |
| 3 | #include <cmath> | |
| 4 | #include <algorithm> | |
| 5 | #include <vector> | |
| 6 | #include <set> | |
| 7 | #include <map> | |
| 8 | #include <stack> | |
| 9 | #include <queue> | |
| 10 | #include <cstdlib> | |
| 11 | #include <cstdio> | |
| 12 | #include <string> | |
| 13 | #include <cstring> | |
| 14 | #include <cassert> | |
| 15 | #include <utility> | |
| 16 | #include <iomanip> | |
| 17 | #define sqr(x) ((x)*(x)) | |
| 18 | ||
| 19 | using namespace std; | |
| 20 | ||
| 21 | const double eps = 1e-9; | |
| 22 | ||
| 23 | double xc, yc, zc, r; | |
| 24 | double xa, ya, za; | |
| 25 | double xb, yb, zb; | |
| 26 | double a, b, c; | |
| 27 | double cosA, cosB, cosC;// angles | |
| 28 | double sinA; | |
| 29 | double mysqrt(double x) {
| |
| 30 | if (x < 0.0 + eps) x = 0.0; | |
| 31 | return sqrt(x); | |
| 32 | } | |
| 33 | double myacos(double x) {
| |
| 34 | if (x < -1.0 + eps) | |
| 35 | x = -1.0; | |
| 36 | else if (x + eps > 1.0) | |
| 37 | x = 1.0; | |
| 38 | return acos(x); | |
| 39 | } | |
| 40 | ||
| 41 | int main() {
| |
| 42 | assert(freopen("input.txt","r",stdin));
| |
| 43 | assert(freopen("output.txt","w",stdout));
| |
| 44 | scanf("%lf%lf%lf%lf", &xc, &yc, &zc, &r);
| |
| 45 | scanf("%lf%lf%lf", &xa, &ya, &za);
| |
| 46 | scanf("%lf%lf%lf", &xb, &yb, &zb);
| |
| 47 | b = sqrt( sqr(xa-xc)+sqr(ya-yc) + sqr(za-zc)); | |
| 48 | c = sqrt( sqr(xa-xb) + sqr(ya-yb) + sqr(za -zb) ); | |
| 49 | a = sqrt( sqr(xc-xb) + sqr(yc-yb) + sqr(zc -zb) ); | |
| 50 | double beta = asin(r/b); | |
| 51 | cosA = (b*b + c*c - a*a) / (2*b*c); | |
| 52 | if ( b + c <= a + eps || c + a <= b + eps ) {
| |
| 53 | printf("%.12lf\n", 0);
| |
| 54 | return 0; | |
| 55 | } | |
| 56 | ||
| 57 | ||
| 58 | double lo = 0, hi = c, x; | |
| 59 | double CO, cosTh, p, cosPhi, q, f; | |
| 60 | int step = 1000; | |
| 61 | while ( step -- ) {
| |
| 62 | x = (hi + lo ) / 2; | |
| 63 | CO = mysqrt(x*x + b*b - 2*x*b*cosA); | |
| 64 | cosTh = (b*b + CO*CO - x*x) / (2 * b * CO); | |
| 65 | p = mysqrt(b*b + r*r - 2*b*r*cosTh); | |
| 66 | cosPhi = (CO*CO + a*a - sqr(c - x)) / (2*CO*a); | |
| 67 | q = mysqrt( r*r + a*a - 2*r*a*cosPhi); | |
| 68 | f = p * ( c - x ) / (q*x); | |
| 69 | if (f < 1.0) | |
| 70 | hi = x; | |
| 71 | else | |
| 72 | lo = x; | |
| 73 | } | |
| 74 | double alpha = myacos( (p*p + b*b - r*r) / (2 * p * b) ); | |
| 75 | double diff = fabs(p * (c-x) - q*x); | |
| 76 | //printf("diff = %.15lf\n", diff);
| |
| 77 | ||
| 78 | //assert( fabs(p * (c-x) - q*x) < 1e-9); | |
| 79 | printf("%.12lf\n", alpha/beta);
| |
| 80 | ||
| 81 | return 0; | |
| 82 | } |