今天又切了一題,做題的同時當然也驗證了各種模板
每次都感覺有所改進
view code
#include點線距離#include
#include
using
namespace std;
const
int maxn = 100010;
const
double eps = 1e-8;
inline int max(int x,int y)
inline double max(double x,double y)
inline double min(double a,double b)
struct point
point operator - (const point& t) const
bool
operator
< (const point &p) const
bool
operator == (const point& t) const
}p[maxn],set[maxn];
struct seg;
struct line ;
inline double dist(point a,point b)
bool cmp(point a,point b)
bool chonghe(point a,point b,point c,point d)//
判斷線段共線,即直線與線段共線
bool inter(point a,point b,point c,point d)//
判斷a,b直線是否與c,d線段相交
bool dotonseg(point p, point s, point e)
line turn(point s, point e)
bool intersect(point p1, point p2, point p3, point p4, point& p)
bool point_in_polygon(point o, point* p, int n)
if ( cross(o, a, b) < -eps && a.y < o.y-eps && o.y < b.y+eps )
t++;
}return t&1;
}bool seg_inst(seg s1, seg s2, point &p)
bool check(seg s1, seg s2, point& pp)
if ( s1.e==s2.s || s1.e==s2.e)
return
false;
}
view code
inline double是否是凸多邊形ppdis(point a,point b)
inline
double
pldis(point a,point l1,point l2)
view code
inline int _sgn(double x)點是否在凸多邊形內或邊上int is_convex(int n,point p);
for(i=0;i1]|s[2];i++)
s[_sgn(cross(p[i],p[(i+1)%n],p[(i+2)%n]))]=0
;
return s[1]|s[2
];}
view code
int inside_convex(point q,int n,point *p);點在任意多邊形內或邊上for(i=0;i1]|s[2];i++)
s[_sgn(cross(p[i],p[(i+1)%n],q))]=0
;
return s[1]|s[2
];}
view code
#include #include#include
using
namespace
std;
const
int maxn = 100010
;const
double eps = 1e-8
;inline
double sgn(double x)
struct
point
}p[maxn],
set[maxn];
inline
double cross(point a,point b,point c)
bool
dotonseg(point p, point s, point e)
bool point_in_polygon(point o, point* p, int
n)
if ( cross(o, a, b) < -eps && a.y < o.y-eps && o.y < b.y+eps )
t++;
}return t&1
;}
計算幾何大模板(持續更新)
計算幾何說起來都是一套一套的,寫起來卻讓人二楞二楞的qwq 接下來直接粘 稍微高階的演算法講解詳見超連結 基本的定義 演算法 include const double eps 1e 7 誤差允許範圍,廣泛用於大小比較 inline double dcmp double x 強烈建議浮點數的大小比較都...
模板整合 及時更新 天坑 計算幾何模板
計算幾何模板要寫的內容真多 我寫煩了 先寫這些放上來吧 include include include include include include define maxdbl 1e20 define eps 1e 9 define pi acos 1 using namespace std st...
計算幾何模板
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 ...