Runaway to a Shadow 幅角相关函数的运用的板子

atan2(y,x):表示点(x,y)的方位角,值域(-pi,p],想跟高中几何象限定义统一就加个pi,

asin,acos返回值都可以用作角度来在方位角上加减,在这基础上就可以很方便地算三角函数了

//#include  
#pragma comment(linker, "/STACK:1024000000,1024000000")   
#include  
#include  
#include  
#include  
#include  
#include                    
#include
#include  
#include  
#include  
#include 
#include
#include
using namespace std;         //

#define ll long long  
#define ull unsigned long long
#define pb push_back  
#define FOR(a) for(int i=1;i<=a;i++) 
#define sqr(a) (a)*(a)
//#define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))
ll qp(ll a,ll b,ll mod){
	ll t=1;while(b){if(b&1)t=t*a%mod;b>>=1;a=a*a%mod;}return t;
}
struct DOT{int x;int y;};
inline void read(int &x){int k=0;char f=1;char c=getchar();for(;!isdigit(c);c=getchar())if(c=='-')f=-1;for(;isdigit(c);c=getchar())k=k*10+c-'0';x=k*f;} 
void ex(){puts("-1");exit(0);}
const int dx[4]={0,0,-1,1};
const int dy[4]={1,-1,0,0};
const int inf=0x3f3f3f3f; 
const ll Linf=0x3f3f3f3f3f3f3f3fll;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double eps=1e-7;

const int maxn=1e6+3;

double dis(double x,double y,double x1,double y1){
	return sqrt(sqr(x-x1)+sqr(y-y1));
}
vector >a;

double x,y,v,t,r;
int n;

int main(){
	scanf("%lf%lf%lf%lf",&x,&y,&v,&t);
	r=v*t;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		double x0,y0,r0;
		scanf("%lf%lf%lf",&x0,&y0,&r0);
		double D=dis(x,y,x0,y0);
		if(D<=r0){
			puts("1.000000");return 0;
		}
		if(r+r0+epsr+eps){
			ang=acos((sqr(r)+sqr(D)-sqr(r0))/(2*D*r));
		}else{
			ang=asin(r0/D);
		}
		angl=angm-ang;angr=angm+ang;
		if(angl<0){
			a.pb(make_pair(angl+2*pi,1));
			a.pb(make_pair(2*pi,-1));
			a.pb(make_pair(0,1));
			a.pb(make_pair(angr,-1));
		}else if(angr>2*pi){
			a.pb(make_pair(angl,1));
			a.pb(make_pair(2*pi,-1));
			a.pb(make_pair(0,1));
			a.pb(make_pair(angr-2*pi,-1));
		}else{
			a.pb(make_pair(angl,1));
			a.pb(make_pair(angr,-1));
		}
	}
	sort(a.begin(),a.end());
	double ans=0;
	double lst=0;
	int now=0;
	for(int i=0;i0)ans+=a[i].first-lst;
		lst=a[i].first;
		now+=a[i].second;
	}
	printf("%.10lf\n",ans/(2*pi));
}























你可能感兴趣的:(计算几何)