计算几何(白书)

二维几何基础

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
/**
atan2(y,x)返回反正切值,[-PI,PI]弧度,求极角
atan(x)返回反正切值,[-PI/2,PI/2]弧度
**/

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){
    return a.x<b.x || (a.x==b.x&&a.y<b.y);
}

int dcmp(double x){
    if(fabs(x)<eps) return 0;
    else return x<0?-1:1;
}

bool operator == (const Point& a,const Point& b){
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}

int main(){

    return 0;
}

猜你喜欢

转载自blog.csdn.net/algzjh/article/details/81605964