• 计算几何板子


    随做题也不一定补充。

    int js(double x)
    {
    	if(Abs(x) < eps) return 0;
    	return x > 0 ? 1 : -1;
    }
    struct point
    {
    	double x,y;
    	
    	point(){}
    	point(double xx,double yy){
    		x = xx;
    		y = yy;
    	}
    	
    	void Get(){scanf("%lf %lf",&x,&y);}
    	
    	void print(){printf("%.2f %.2f
    ",x,y);}
    	
    	point operator + (const point &C){return point(x+C.x,y+C.y);}
    	point operator - (const point &C){return point(x-C.x,y-C.y);}
    	point operator * (const double C){return point(x*C,y*C);}
    	bool operator < (const point &px)const{
    		if(x != px.x) return x < px.x;
    		return y < px.y;
    	}
    	bool operator == (const point &C)const{
    		return (!js(x-C.x)) && (!js(y-C.y));
    	}
    	
    	point rot90(){return point(-y,x);}
    }p[MAXN];
    double cross(point A,point B){return A.x*B.y-A.y*B.x;}
    double dot(point A,point B){return A.x*B.x+A.y*B.y;}
    double len(point A){return sqrt(A.x*A.x+A.y*A.y);}
    
    bool OnSegment(point A,point B1,point B2)
    {
    	point c1 = B1 - A,c2 = B2 - A;//向量
    	if(js(cross(c1,c2))) return 0;//判断向量共线
    	if(js(c1.x*c2.x) <= 0 && js(c1.y*c2.y) <= 0) return 1;//判断向量异向
    	return 0;
    }
    bool check(point A1,point A2,point B1,point B2)
    {
    	if(OnSegment(A1,B1,B2) || OnSegment(A2,B1,B2)) return 1;
    	if(OnSegment(B1,A1,A2) || OnSegment(B2,A1,A2)) return 1;
    	point C1 = A2-A1,C2 = B2-B1;
    	if(!js(cross(C1,C2))) return 0;
    	double c1 = cross(A2-A1,B1-A1),c2 = cross(A2-A1,B2-A1),
    		   c3 = cross(B2-B1,A1-B1),c4 = cross(B2-B1,A2-B1);
    	return (js(c1) * js(c2) <= 0) && (js(c3) * js(c4) <= 0);
    }
    point inter(point A1, point A2, point B1, point B2)//intersection
    {
        point c1 = A2 - A1, c2 = B2 - B1;
        double t = cross(c2,(A1 - B1)) / cross(c1,c2);
        return c1*t+A1;
    }
    point Cir(point A,point B,point C){return inter((A+B)/2,(B-A).rot90(),(A+C)/2,(C-A).rot90());}//三点求圆心(不共线) 
    double sq(double x){return x*x;}//平方
    struct line
    {
    	double A,B,C;//Ax+By+C=0
    	line(){}
    	line(double A1,double B1,double C1){
    		A = A1;
    		B = B1;
    		C = C1; 
    	}
    };
    double PLdis(point P,line L){return Abs(L.A*P.x + L.B*P.y + L.C) / sqrt(sq(L.A)+sq(L.B));}//点到线距离
    double CirInter(Circle A,Circle B)//圆交? 
    {
    	double cha = Abs(A.r-B.r),he = Abs(A.r+B.r);
    	double dis = len(B.O-A.O);
    	if(dis >= he) return 0;//相离 & 外切 
    	if(dis <= cha) return Min(A.r,B.r) * Min(A.r,B.r) * PI;//内含 & 内切 
    	if(B.r > A.r) swap(A,B);
    	double A1 = acos((A.r*A.r+dis*dis-B.r*B.r)/(2*A.r*dis)); 
    	double B1 = acos((B.r*B.r+dis*dis-A.r*A.r)/(2*B.r*dis)); 
    	return A1*A.r*A.r + B1*B.r*B.r - A.r*dis*sin(A1);
    }
    
  • 相关阅读:
    python爬虫之Anaconda安装
    python爬虫之scrapy安装(一)
    python爬虫之redis环境简单部署
    python爬虫之Phantomjs安装和使用
    python爬虫之win7Mongod安装使用
    python爬虫之PyQuery的基本使用
    python爬虫之xpath的基本使用
    python爬虫之git的使用(windows下pycharm使用)
    Sass教程
    Vue.js教程—1.介绍和安装
  • 原文地址:https://www.cnblogs.com/PPLPPL/p/15114077.html
Copyright © 2020-2023  润新知