|
|
вернуться в форумHelp! WA! #include <fstream.h> #include <math.h> ifstream fin("thread.dat"); //#define fin cin const double M_PI = 3.1415926535897932384626433832795; class Vec3D { public: double x,y,z; Vec3D() {}; Vec3D(double X,double Y,double Z): x(X), y(Y), z(Z) {} Vec3D operator-(const Vec3D&a){return Vec3D(x-a.x,y-a.y,z-a.z);} double operator*(const Vec3D&a){return x*a.x+y*a.y+z*a.z;} void operator/=(double a){x/=a;y/=a;z/=a;} double module(){return sqrt(x*x+y*y+z*z);} }; inline double sqr(double x) {return x*x;} double distance(Vec3D &a, Vec3D &b) {return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z));} void main() { Vec3D a,b,c; double r; fin >> a.x >> a.y >> a.z; fin >> b.x >> b.y >> b.z; fin >> c.x >> c.y >> c.z; fin >> r; double da=distance(a,c), ta=sqrt(da*da-r*r); double db=distance(b,c), tb=sqrt(db*db-r*r); double alfa=asin(r/da); double beta=asin(r/db); /// alfa is angle between AC and tangent Vec3D ax=a-c, bx=b-c; ax/=ax.module(); bx/=bx.module(); double gama=acos(ax*bx); // gama is angle ACB double delta=gama+alfa+beta-M_PI; cout.precision(2); cout << (delta<0 ? distance(a,b) : delta*r+ta+tb) << endl; } Re: Help! WA! You should have a couple more "if"'s in your program |
|
|