zoukankan      html  css  js  c++  java
  • 计算几何基础模板

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #define eps 1e-8
    using namespace std;
    typedef long long ll;
    int sgn(double x){
        if(fabs(x)<eps) return 0;
        else if(x<0) return -1;
        else return 1;
    }
    struct Point{
        double x,y;
        Point(){}
        Point(double _x,double _y){x=_x;y=_y;}
        Point operator-(const Point &b)const{return Point(x-b.x,y-b.y);}
        double operator^(const Point &b)const{return x*b.y-y*b.x;}
        double operator*(const Point &b)const{return x*b.x+y*b.y;}
    };
    struct Line{
        Point s,e;
        Line(){}
        Line(Point _s,Point _e){s=_s,e=_e;}
        pair<int,Point>operator&(const Line &b)const{
            Point res=s;
            if(sgn((s-e)^(b.s-b.e))==0){
                if(sgn((s-b.e)^(b.s-b.e))==0) return make_pair(0,res);
                else return make_pair(1,res);
            }
            double t=((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
            res.x+=(e.x-s.x)*t;
            res.y+=(e.y-s.y)*t;
            return make_pair(2,res);
        }
    };
    bool inter(Line l1,Line l2){
        return 
        max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x)&&
        max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x)&&
        max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y)&&
        max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y)&&
        sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e))<=0&&
        sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=0;
    }
    
    int main(){
        return 0;
    }
  • 相关阅读:
    词法分析
    关于编译原理
    词法分析
    编译原理
    对编译原理的一些看法
    spring整合struts2
    spring整合javaWeb
    spring整合hibernate
    spring-transaction事务
    spring-jdbc
  • 原文地址:https://www.cnblogs.com/elpsycongroo/p/8884006.html
Copyright © 2011-2022 走看看