1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<climits> #include<vector> #include<cstdio> #include<cmath> #include<queue>
using namespace std;
inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(!isdigit(x)) { if(x=='-')bj=-1; x=getchar(); } while(isdigit(x)) { num=num*10+x-'0'; x=getchar(); } return num*bj; }
const int maxn=105; const double pi=acos(-1);
struct Point { double x,y,z; Point(double x=0,double y=0,double z=0):x(x),y(y),z(z) {} Point operator + (const Point& b) { return Point(x+b.x,y+b.y,z+b.z); } void operator += (const Point& b) { *this=*this+b; } Point operator - (const Point& b) { return Point(x-b.x,y-b.y,z-b.z); } void operator -= (const Point& b) { *this=*this-b; } Point operator * (double c) { return Point(x*c,y*c,z*c); } void operator *= (double c) { *this=*this*c; } Point operator / (double c) { return Point(x/c,y/c,z/c); } void operator /= (double c) { *this=*this/c; } double length() { return sqrt(x*x+y*y+z*z); } } p[maxn];
typedef Point Vector;
double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y+a.z*b.z; }
Vector Cross(Vector a,Vector b) { return Vector(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x); }
double Triple(Vector a,Vector b,Vector c) { return Dot(a,Cross(b,c)); }
double Cal(Vector a,Vector b,Vector c) { Vector u=Cross(a,b),v=Cross(a,c); return acos(Dot(u,v)/u.length()/v.length()); }
int n,f,F[maxn][maxn];
int main() { n=Get_Int(); f=Get_Int(); for(int i=1; i<=n; i++) { double x,y,z; scanf("%lf%lf%lf",&x,&y,&z); p[i]=Point(x,y,z); } for(int i=1; i<=f; i++) { F[i][0]=Get_Int(); for(int j=1; j<=F[i][0]; j++)F[i][j]=Get_Int(); } double vol=0; Vector ctr; for(int i=1; i<=f; i++) for(int j=2; j<F[i][0]; j++) { Vector ci=p[F[i][1]]+p[F[i][j]]+p[F[i][j+1]]; double vi=Triple(p[F[i][1]],p[F[i][j]],p[F[i][j+1]]); vol+=vi; ctr+=ci*vi; } ctr/=vol*4; for(int i=1; i<=n; i++)p[i]-=ctr; for(int i=1; i<=f; i++) { double ans=0; for(int j=2; j<F[i][0]; j++)ans+=Cal(p[F[i][j]],p[F[i][j-1]],p[F[i][j+1]]); ans+=Cal(p[F[i][F[i][0]]],p[F[i][F[i][0]-1]],p[F[i][1]])+Cal(p[F[i][1]],p[F[i][F[i][0]]],p[F[i][2]]); printf("%0.7lf\n",(ans-(F[i][0]-2)*pi)/(4*pi)); } return 0; }
|