計算幾何模板

2021-07-16 02:48:56 字數 3252 閱讀 8565

「`

// 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) : x(x), y(y)

};pt operator - (pt a, pt b)

pt operator + (pt a, pt b)

pt operator * (int a, pt p)

pt operator * (pt p, int a)

ints

qr(int x)

int norm(pt p)

double dist (pt a, pt b)

double len(pt p)

void print(pt p)

int dot(pt a, pt b)

int det(pt a, pt b)

int det(pt a,pt b,pt o)

double triarea(pt a, pt b, pt c)

//double版

struct pt

pt(double x, double y) : x(x), y(y)

};double s

qr(double x)

pt operator - (pt a, pt b)

pt operator + (pt a, pt b)

pt operator * (double a, pt p)

pt operator * (pt p, double a)

double norm(pt p)

double dist (pt a, pt b)

void print(pt p)

double len(pt p)

double dot(pt a, pt b)

double det(pt a, pt b)

double det(pt a,pt b,pt o)

double triarea(pt a, pt b, pt c)

pt rotate(pt p, double a)

struct sg 

sg(pt s, pt t) : s(s), t(t)

sg(double a, double b, double c, double d) : s(a, b), t(c, d)

};bool ptonsegment(pt s, pt t, pt a)

bool ptonsegment(pt p, pt a, pt b)

bool ptonline(pt p, pt s, pt t)

bool sgonline(sg seg, pt ls, pt lt)

pt ptlineproj(pt s, pt t, pt p)

bool parallel(pt a, pt b, pt s, pt t)

double ptsegmentdist(pt a, pt b, pt p)

bool segcro(sg u,sg v) /** 判斷線段是否相交 */

//由三個點求平面方程

//平面方程a*x+b*y+c*z+d=0

;int a = ((a[2].y-a[1].y)*(a[3].z-a[1].z)-(a[2].z-a[1].z)*(a[3].y-a[1].y));

int b = ((a[2].z-a[1].z)*(a[3].x-a[1].x)-(a[2].x-a[1].x)*(a[3].z-a[1].z));

int c = ((a[2].x-a[1].x)*(a[3].y-a[1].y)-(a[2].y-a[1].y)*(a[3].x-a[1].x));

int d = -(a * a[1].x + b * a[1].y + c * a[1].z);

//重心

pt ********masscenter(pt a, pt b, pt c)

//外心

pt circumcenter(pt a, pt b, pt c)

//垂心

pt orthocenter(pt a, pt b, pt c)

#define nxt(x) ((x+1)%n)

struct polygon

polygon(vector

_poi):poi(_poi){}

int size()

};int ptinpolygon(pt p, polygon &a)

k = det(a.poi[nxt(i)]-a.poi[i], p-a.poi[i]);//double時要加sgn

d1 = a.poi[i].y - p.y;

d2 = a.poi[nxt(i)].y - p.y;

if (k > 0 && d1 <= 0 && d2 > 0) num++;

if (k < 0 && d2 <= 0 && d1 > 0) num--;

}return num != 0;

}

typedef

vector

convex;

typedef

vector

polygon;

// 排序比較函式,水平序

bool comp_less(pt a, pt b)

int k = m;

for (int i = int(a.size()) - 2; i >= 0; --i)

res.resize(m);

if (a.size() > 1) res.resize(m-1);

}

//求多邊形面積

double s(polygon &p)

//求凸包的最遠距離

double convex_diameter(const convex &a, int &first, int &second)

return ans;

}

計算幾何模板

include define vct point using namespace std const double pi atan2 0,1 const double eps 1e 8 int sgn double d struct point bool operator point b const...

計算幾何模板

多圓面積交 typedef long long ll typedef unsigned long long ull typedef vector vi const int inf 0x3f3f3f3f const double eps 1e 10 const int mod 100000007 co...

計算幾何 模板

include include include include typedef double db const db eps 1e 9 const db pi acos 1 判斷符號 inline intsign db ps 比較大小 inline intcmp db ps,db b 點 struc...