Computational Geometry function summary

Front tips, personal use, construction, incomplete.


//实数大小比较
const double EPS=1e-9;
inline int sign(double a) {return a<-EPS?-1:a>EPS;}
inline int cmp(double a,double b) {return sign(a-b);}

//向量的定义 

struct Point
{
    double x,y;
    Point(double xx,double yy) {x=xx,y=yy;}
    Point operator+(Point p) 
    {
        return Point(x+p.x,y+p.y);
    }
    Point operator-(Point p)
    {
        return Point(x-p.x,y-p.y);
    }
    Point operator*(double d)
    {
        return Point(x*d,y*d);
    }
    Point operator/(double d)
    {
        return Point(x/d,y/d);
    }
    bool operator<(Point p)const
    {
        int c=cmp(x,p.x);
        if(c) return c==-1;
        return cmp(y,p.y)==-1;
    }
    bool operator==(Point p)const
    {
        return cmp(x,p.x)==0&&cmp(y,p.y)==0;
    }
}

//点乘与叉乘

double dot(Point b)
{
    return x*p.x+y*p.y;
 } 
 
double det(Point b)
{
    return x*p.y-y*p.x;
}

Guess you like

Origin www.cnblogs.com/tztqwq/p/11256481.html