zoukankan      html  css  js  c++  java
  • Runaway to a Shadow 幅角相关函数的运用的板子

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

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

    //#include<bits/stdc++.h>  
    #pragma comment(linker, "/STACK:1024000000,1024000000")   
    #include<stdio.h>  
    #include<algorithm>  
    #include<queue>  
    #include<string.h>  
    #include<iostream>  
    #include<math.h>                    
    #include<stack>
    #include<set>  
    #include<map>  
    #include<vector>  
    #include<iomanip> 
    #include<bitset>
    #include<time.h>
    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<pair<double,int> >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+eps<D)continue;
    		double ang,angl,angr;
    
    		double angm=atan2(y0-y,x0-x);
    		if(angm<0)angm+=2*pi;		//[0,2*pi]
    
    		if(D>r+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;i<a.size();i++){
    		if(now>0)ans+=a[i].first-lst;
    		lst=a[i].first;
    		now+=a[i].second;
    	}
    	printf("%.10lf
    ",ans/(2*pi));
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  • 相关阅读:
    【重学计算机】计组D2章:数据表示
    【重学计算机】计组D1章:计算机系统概论
    计算机底层原理杂谈(白话文)
    阿里云安装wordpress遇到的问题
    wordpress数据表结构
    家用计费系统ER图
    java 类中的属性为什么一般都是私有的
    centos 软件库安装
    linux下启动tomcat----Cannot find ./catalina.sh
    jfreechart图表汉字乱码问题解决方案
  • 原文地址:https://www.cnblogs.com/Drenight/p/8611185.html
Copyright © 2011-2022 走看看