計算幾何 模板

2022-06-03 08:48:12 字數 2351 閱讀 5284

基礎模板。

#include #define fr friend

const double pi = acos(-1);

const double eps = 1e-9;

const double inf = 1e9;

const int n = 100000;

int dcmp(double x)

// 這裡還是建議寫成 fabs(x) <= eps,因為當 eps = 0 時良定義

struct point;}

fr point operator - (const point &a, const point &b) ;}

fr point operator * (const point &a, double k) ;}

fr point operator / (const point &a, double k) ;}

fr void operator += (point &a, const point &b)

fr void operator -= (point &a, const point &b)

fr void operator *= (point &a, double k)

fr void operator /= (point &a, double k)

fr double operator * (const point &a, const point &b) // dot

fr double operator ^ (const point &a, const point &b) // cross

fr bool operator == (const point &a, const point &b)

fr bool operator < (const point &a, const point &b)

fr double angle(const point &a)

fr double length(const point &a)

fr double dist(const point &a, const point &b)

fr double area(const point &a, const point &b, const point &c)

fr double area(point *a, int n)

fr bool on_line(const line &l, const point &p)

fr bool on_segment(const line &l, const point &p)

fr bool same_side(const line &l, const point &p1, const point &p2) // proper same_side

fr bool is_intersect_segment(const line &l1, const line &l2) // proper intersect

fr double dist_p_line(const line &l, const point &p)

fr double dist_p_segment(const line &l, const point &p)

fr double dist_s_segment(const line &l1, const line &l2)

fr point intersect_line(const line &l1, const line &l2)

fr point projection(const line &l, const point &p)

fr point reflection(const line & l, const point &p)

};void convex(point *a, int n, point *b, int &m)

o = m;

for(int i=k-2;i>=0;i--)

b[--m] = (point);}/*

求凸包注意兩個常常需要討論的點:

(1)n 個點共線。

(2)凸包上的邊是否允許多點共線(**中給的是不允許共線的版本)。

*/namespace half_plane

else ql[++t] = x;

if( s < t ) qp[t-1] = intersect_line(ql[t-1], ql[t]);

} bool half_plane(line *a, int n) //只判斷是否存在半平面交,其他用途同理

/* 用半平面交時注意乙個細節:直線上的點是否在半平面上。

主要是最後半平面交可能退化成單點,如果按上面**來寫就是無解的

*/}int main()

計算幾何模板

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 ...

計算幾何模板

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...