計算幾何基本模板

2021-07-15 14:13:33 字數 1284 閱讀 6253

上傳一下計算幾何的基本模板,自己也可以看

#include #include #include using namespace std;

struct point;

typedef point vector;

point::point(double x, double y)

//向量與向量的+ - 點積 叉積

vector operator +(const vector &a, const vector &b)

vector operator -(const vector &a, const vector &b)

double dot(const vector &a, const vector &b)

double cross(const vector &a, const vector &b)

//向量關係運算子

bool operator <(const vector &a, const vector &b)

int dcmp(double x)

bool operator == (const vector &a,const vector &b)

//向量與數字的乘除

vector operator *(const vector &a,double p)

vector operator /(const vector &a,double p)

//向量的模

double length(const vector &a)

double angle (const vector &a,const vector &b)

point getlineintrersection(point p, vector v, point q, vector w)

double distancetoline(point p, point a, point b)

double distancetosegment(point p, point a, point b)

double distancemaxtosegment(point p, point a, point b)

//線段是否「正規相交」,即交點不在四個端點上

bool segmentproperintersection(point a1, point a2, point b1, point b2)

return dcmp(cross(a1 - p, a2 - p)) == 0 && dcmp(dot(a1 - p, a2 - p) < 0) ;

}

計算幾何基本模板

const double eps 1e 8 const double pi acos 1.0 判浮點數符號 int sgn double x point定義 struct point point double x double y point operator const point b const...

計算幾何基本模板

待更新。include include includeusing namespace std const double pi acos 1 const double eps 1e 8 實數精度 點結構型別 struct point 線段結構型別 struct lineseg struct line ...

計算幾何模板

sgn返回x經過eps處理的符號,負數返回 1,正數返回1,x的絕對值如果足夠小,就返回0。const double eps 1e 8 int sgn double x double mysqrt double x pt是point的縮寫 int版 struct pt pt int x,int y ...