第二章所用來源程式 【Fuction檔案中的程式】

來源:互聯網
上載者:User
 #include"Queue.h" static void  PT_detec(long double x ,long double y ,long double z ); static  bool intersect(QueueElementType a, QueueElementType b); static bool intersect(QueueElementType a, square_A b); static bool inter(QueueElementType a, QueueElementType b); static long double area_nonself(QueueElementType a[]); extern unsigned int num_d;void  PT_detec(long double x, long double y, long double r){ if(r<r0)  return ; else {  sum+=4;  for(int k1=0;k1<=1;k1++)   for(int k2=0;k2<=1;k2++)   {    QueueElementType w;    w.x=x+pow(-1.0,k1)*r/2;    w.y=y+pow(-1.0,k2)*r/2;    w.r=r/2;    int flag1=0;      int flag2=0;    for(int i=0;i<NS;i++)    {     if(intersect(w,self[i]))     {      flag1=1;      if(inter(w,self[i]))      {       flag2=1;       break;      }     }    }    if(flag1==0){     detector.push_back(w);     s_all+=4*w.r*w.r;    }    else{     if(0==flag2)                        {      EnQueue(p1,w);     }    }   } }}bool intersect(QueueElementType a, QueueElementType b){   if((a.x-a.r)>(b.x+b.r)||(a.x+a.r)<(b.x-b.r))    return false; else  if((a.y-a.r)>(b.y+b.r)||(a.y+a.r)<(b.y-b.r))   return false;  else   if((b.x<a.x+a.r)&&(b.x>a.x-a.r))    return true;   else    if((b.y<a.y+a.r)&&(b.y>a.y-a.r))     return true;      else    {      if(b.x<a.x)      a.x=a.x-a.r;     else      a.x=a.x+a.r;     if(b.y<a.y)      a.y=a.y-a.r;     else      a.y=a.y+a.r;     if(sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))>b.r)      return false;     else      return true;    } }bool intersect(QueueElementType a, square_A b){   if((a.x-a.r)>b.x||(a.x+a.r)<b.x)  return false; else  if((a.y-a.r)>b.y||(a.y+a.r)<b.y)   return false;  else return true;}bool inter(QueueElementType a, QueueElementType b) { long double d; d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); if((b.r-d)>=(a.r*sqrt(2.0)))   return true; else  return false;}static  long double area_nonself(QueueElementType a[]){ long double x; long double y; long double r; int t=0; int   s_num=0; while(t<100000) {  t++;  x=rand()/(double)(RAND_MAX+1);  y=rand()/(double)(RAND_MAX+1);  for(int i=0;i<NS;i++)  {   r=sqrt((a[i].x-x)*(a[i].x-x)+(a[i].y-y)*(a[i].y-y));   if(r<rs)   {    s_num++;    break;   }  } } return (100000-s_num)/(double)100000;}static long double _max(long double data[]){ double _max = 0; for(int i=0; i<n_time; i++)if(data[i]>_max)_max = data[i]; return _max;}static long double _min(long double data[]){ double _min = data[0]; for(int i=0; i<n_time; i++)if(data[i]<_min)_min = data[i]; return _min;}static long double mean(long double data[]){ double _mean = 0; for(int i=0; i<n_time; i++)_mean += data[i]; return _mean/n_time;}static long double sd(long double data[],long double mean){ double sd = 0; double tmp; for(int i=0; i<n_time; i++) {  tmp = data[i]-mean;  sd += tmp*tmp; } return sqrt(sd/n_time);}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.