向量

struct Point{
    double x,y;
    Point(double x=0, double y=0):x(x),y(y) {}  //构造函数,方便代码编写 
};

typedef Point Vector; //用别名区分点与向量

//向量+向量=向量, 点+向量=点 
Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y); }
//点-点=向量 向量-向量=向量
Vector operator - (Point A, Point B){ return Vector(A.x+B.x, A.y+B.y); }
//向量*数=向量
Vector operator * (Vector A, double p){return Vector(A.x*p, A.y*p); } 
//向量/数=向量
Vector operator / (Vector A, double p){return Vector(A.x/p, A.y/p); }

bool operator < (const Point &a, const Point &b){//重载'<',先排x后排y,亦可以看作以极角排序 
    return a.x < b.x || (a.x==b.x && a.y

你可能感兴趣的:(向量)