class
cvector
;cvector operator
+(cvector p, cvector q)
cvector operator
-(cvector p, cvector q)
cvector operator*(
double k, cvector p)
double
operator
*(cvector p, cvector q)
double
length
(cvector p)
cvector unit
(cvector p)
double
project
(cvector p, cvector n)
double
dot(cvector p, cvector q)
double
operator
^(cvector p, cvector q)
class
cpoint
;class
cline
;double pi =
acos(-
1);double inf =
1e20
;double eps =
1e-6
;//精度不是越高越好
bool
iszero
(double x)
bool
flarger
(double a,
double b)
bool
fless
(double a,
double b)
cvector operator
-(cpoint b, cpoint a)
// c = a – b;
cpoint operator
+(cpoint a, cvector p)
// p = p + v; p是點,v是向量
double
dist
(cpoint p, cpoint q)
double
dist
(cpoint p, cline l)
cpoint rotate
(cpoint b, cpoint a,
double alpha)
intsideofline
(point p, point a, point b)
cline vertical
(cpoint p, cline l)
cpoint foot
(cpoint p, cline l)
cpoint intersect
(cline l, cline m, string msg)
return m.a + x /
(x + y)
*(m.b – m.a);}
//即便線段 l.a->l.b和 m.a->m.b沒交點,也適用
double
cross
(const vector &v1,
const vector &v2)
bool
isformalcross
(point p1, point p2, point p3, point p4)
struct seg //線段
//直線兩點式方程 (y-y1)/(y2-y1) = (x-x1)/(x2-x1)
double
getx
(double y)
double
gety
(double x)};
pair<
int, point>
crosspoint
(seg s1, seg s2)if(
!(iszero
(cross
(p2 - p1, p3 - p4)))
)if(!
iszero
(distance
(p1, s2)))
return
make_pair(5
,point(0
,0))
;//平行
//下面都是共線,且有公共點if(
pointinseg
(p1, s2)
)return
make_pair(6
, p1);if
(pointinseg
(p2, s2)
)return
make_pair(6
, p2);if
(pointinseg
(p3, s1)
)return
make_pair(6
, p3);if
(pointinseg
(p4, s1)
)return
make_pair(6
, p4)
;return
make_pair(7
,point(0
,0))
;//共線,且無公共點
}bool
pointinseg
(point p, seg l)
bool
flesseq
(double a,
double b)
double
angle
(cline l, cline m)
計算幾何模板
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...