POJ 1279 || Art Gallery(半平面交求核面积

注意下一输入的点是逆时针或者顺时针,用面积判定一下是正负就可以啦,统一调整一下

然后算出半平面交核的点集,求面积一下就OK了~

#include
#include
#include
#include
using namespace std;
const double eps = 1e-8;
struct Point{
    double x,y;
    Point(double xx=0.0,double yy=0.0):x(xx),y(yy){}
    Point operator - (const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    Point operator +(const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator /(const double &b)const{
        return Point(x/b,y/b);
    }
    Point operator *(const double &b)const{
        return Point(x*b,y*b);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
}p[1505];
typedef Point myvec;
double cross(myvec a,myvec b){
    return a^b;
}
struct Line{
    Point p;
    myvec v;
    double ang;
    Line(){}
    Line( Point pp,myvec vv):p(pp),v(vv)
    {
        ang = atan2(v.y,v.x);
    }
    bool operator < (const Line &l)const{
        return ang < l.ang;
    }

}L[1505];
//点p在有向直线L的左边(线上不算)
bool on_left( Line l,Point p){
    return cross(l.v,p-l.p)>0;
}
//直线交点 假设交点唯一存在
Point get_inter_section(Line a,Line b){
    myvec u = a.p - b. p;
    double t = cross(b.v,u)/cross(a.v,b.v);
    return a.p+a.v*t;

}
int half_plane_inter_section(Line *L,int n,Point *poly){
    sort(L,L+n);//级角排序
    int fir,lst;//双向队列的第一个元素和最后一个元素的下标
    Point *p = new Point[n];//p[i] 为q[i]和q[i+1]的交点
    Line *q = new Line[n];//双端队列
    q[ fir = lst = 0 ] = L[0];//双端队列初始化为只有一个半平面的L[0]
    for( int i =1; i 


你可能感兴趣的:(计算几何,POJ,1279,Art,Gallery,半平面交求核面积)