• 计算几何


    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const double eps=1e-6;
    int dcmp(double a)
    {
        if(fabs(a)<=eps)return 0;
        else return a>0?1:-1;
    }
    struct Vector
    {
        double x,y;
        Vector operator +(const Vector &a)const{return (Vector){x+a.x,y+a.y};}
        Vector operator -(const Vector &a)const{return (Vector){x-a.x,y-a.y};}
        Vector operator *(const double &a)const{return (Vector){x*a,y*a};}
        Vector operator /(const double &a)const{return (Vector){x/a,y/a};}
    };
    double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
    double Length(Vector a){return sqrt(dot(a,a));}
    double Angle(Vector a,Vector b){return acos(dot(a,b)/Length(a)/Length(b));}
    double Xmult(Vector a,Vector b){return a.x*b.y-b.x*a.y;}
    double Area(Vector a,Vector b,Vector c){return Xmult(b-a,c-a);}
    int Intersec(Vector a,Vector b,Vector c,Vector d)
    {
        if(max(a.x,b.x)<min(c.x,d.x))return false;
        if(max(a.y,b.y)<min(c.y,d.y))return false;    
        if(max(c.x,d.x)<min(a.x,b.x))return false;
        if(max(c.y,d.y)<min(a.y,b.y))return false;
        if(Area(c,b,a)*Area(b,d,a)<0)return false;
        if(Area(a,d,c)*Area(d,b,c)<0)return false;
        return true;
    }
    Vector Interpoint(Vector a,Vector b,Vector c,Vector d)
    {
        Vector u=a-c;
        double t=Xmult(d,u)/Xmult(b,d);
        return a+v*t;
    }
    double Distoline(Vector p,Vector a,Vector b)
    {
        Vector v1=b-a,v2=p-a;
        return fabs(Xmult(v1,v2)/Length(v1));
    }
    int Onseg(Vector p,Vector a,Vector b){return dcmp(Xmult(a-p,b-p))==0 && dcmp(dot(a-p,b-p))<0;}
    int main()
    {
        
    }
    View Code

    计算几何常用模板 码着

  • 相关阅读:
    Smartform中表(table)的行间距设置
    ◆◆0Smartform中如何设置背景阴影色(Shading)
    ◆◆0如何在Smartforms中设置左右对齐
    如何在smartform中设置行间距
    ◆◆0如何在smartform中的table节点插入分页
    ◆◆0如何翻译smartform中的Text module
    如何在smartforms中插入复选框(checkbox)
    ◆◆0选择屏幕-SELECTION-SCREEN(一)
    科研呢喃-2
    遇到杠精,浪费时间
  • 原文地址:https://www.cnblogs.com/Kong-Ruo/p/7920897.html
Copyright © 2020-2023  润新知