【算法】计算几何

刚写了一个计算几何的模板,这样可以减少很多的函数,实现起来也很清楚,以后自己就这样写好了……

// 常用计算
#define vector point

struct point
{
    double x, y;
    point( double x = 0, double y = 0 ): x( x ), y( y ) { }
};

vector operator +  ( vector A, vector B ) { return vector( A.x + B.x, A.y + B.y ); }
vector operator -  ( vector A, vector B ) { return vector( A.x - B.x, A.y - B.y ); }
vector operator >> ( vector A, double a ) { return vector( A.x * cos(a) - A.y * sin(a), A.x * sin(a) + A.y * cos(a) ); }
double operator *  ( vector A, vector B ) { return A.x * B.x + A.y * B.y; }
double operator |  ( vector A, vector B ) { return A.x * B.y - A.y * B.x; }
double operator !  ( vector A           ) { return sqrt( A.x * A.x + B.x + B.x ); }
double operator ^  ( vector A, vector B ) { return acos( A * B / !A / !B ); }



你可能感兴趣的:(模板,运算符重载,计算几何)