[计算几何]一些模型的积累

计算几何基本模板

struct Vec{
    double x, y;
    Vec() {}
    Vec(double _x, double _y) : x(_x), y(_y) {}
    inline double angle() const{return atan2(y,x);}
    inline double len() const{return sqrt(x*x+y*y);}
    inline Vec l_rot() const{return Vec(-y,x);}
    inline Vec r_rot() const{return Vec(y,-x);}
};
inline Vec operator + (const Vec &a, const Vec &b){return Vec(a.x+b.x,a.y+b.y);}
inline Vec operator - (const Vec &a, const Vec &b){return Vec(a.x-b.x,a.y-b.y);}
template<typename T> inline Vec operator * (const Vec &a, T b){return Vec(a.x*b,a.y*b);}
template<typename T> inline Vec operator * (T a, const Vec &b){return Vec(a*b.x,a*b.y);}
template<typename T> inline Vec operator / (const Vec &a, T b){return Vec(a.x/b,a.y/b);}
inline double dot (const Vec &a, const Vec &b){return a.x*b.x+a.y*b.y;}
inline double cross (const Vec &a, const Vec &b){return a.x*b.y-a.y*b.x;}
typedef Vec Poi;
inline bool gt(double x, double y) {return x-y>eps;}
inline bool lt(double x, double y) {return x-y<eps;}
inline bool eq(double x, double y) {return abs(x-y)<=eps;}
inline bool ge(double x, double y) {return x-y>=eps;}
inline bool le(double x, double y) {return x-y<=eps;}
inline bool eq0(double x) {return abs(x)<=eps;}
inline bool gt0(double x) {return x>eps;}
inline bool lt0(double x) {return x<-eps;}

//三角形外心
//设a(x1,y1),b(x2,y2),c(x3,y3),外心o(x,y)
//由定义ao=bo,bo=co,得到一个二次式
//换元 Ax=2(x2-x1),Ay=2(x3-x2),
// Bx=2(y2-y1),By=2(y3-y2),
// Cx=x2^2+y2^2-x1^2-y1^2,Cy=x3^2+y3^2-x2^2-y2^2
//得到x=(CxBy-CyBx)/(AxBy-AyBx)
// y=(CxAy-CyAx)/(BxAy-ByAx),是叉积的形式
inline Poi solve(Poi a, Poi b, Poi c){
    Poi A = 2*Vec(b.x-a.x, c.x-b.x);
    Poi B = 2*Vec(b.y-a.y, c.y-b.y);
    Poi C = Vec(sqr(b.len())-sqr(a.len()), sqr(c.len())-sqr(b.len()));
    double x = cross(C, B), y = cross(C, A), M = cross(A, B);
    return Vec(x,-y)/M;
}

点集三角形覆盖计数

给一个点集,统计覆盖了原点的三角形个数
:枚举点 i ,原点与 i 连线两侧分成两个半平面,同一个半平面内的任意两点与 i 组成的三角形均不包含原点,考虑到重复计数,只需考虑同一方向的半平面即可不重不漏,按极角序扫描可以将平方优化到线性
(BZOJ1914)

点集凹四边形计数

给一个点集,统计凹四边形的数量
:枚举中间凹点,转化为点集三角形覆盖计数问题
(BZOJ1913)

最小圆覆盖

给一个点集,求一个圆使得所有点被覆盖且圆最小
:随机增量法,参见这里http://wenku.baidu.com/view/162699d63186bceb19e8bbe6.html
(BZOJ2823)

To be continued…

你可能感兴趣的:(计算几何)