計算幾何模板二(矩形、圓)
#include#include#include#includeusing namespace std;
#define sgn(x) (((x)<0)?(-1):(1))
#define eps 1e-8
#define inf 1e10
#define pi (acos(-1.0))
double deg2rad(double deg)
double rad2deg(double rad)
double sin(double deg)
double cos(double deg)
double arcsin(double val)
double arccos(double val)
//點struct point
point(double _x,double _y):x(_x),y(_y){};
};//兩個點的距離
double distance(const point &a,const point &b)
//線段
struct seg
; seg(point _a,point _b):a(_a),b(_b){};
};//矩形
//矩形的線段
// 2
// ---------------- b
// | |
// 3 | | 1
// | |
// a ----------------
// 0
struct rect
; rect(const point &_a,const point &_b)
};//矩形化標準
rect stdrect(const rect &q)
if(p.a.x>p.b.y)
return p;
}//根據下標返回矩形的邊
seg edge(const rect &rect,int idx)
return edge;
}//矩形的面積
double area(const rect &rect)
//兩個矩形的公共面積
double commonarea(const rect &a,const rect &b)
return area;
}//圓
struct circle
; circle(double _x,double _y,double _r):x(_x),y(_y),r(_r){};
};//圓心
point center(const circle &circle)
//圓的面積
double area(const circle &circle)
//兩個圓的公共面積
double commonarea(const circle &a,const circle &b)
else if(d<=m.r-n.r)
return area;
}//判斷圓是否在矩形內(不允許相切)
bool isincircle(const circle &circle,const rect &rect)
計算幾何 圓 二維模板
include include include include include define fir first define sec second using namespace std const double eps 1e 8 const double pi acos 1.0 int dcmp...
二維計算幾何模板 圓
include include include include include include include include include include include include define eps 1e 6 log x define e exp 1.0 define mod 1000...
計算幾何 二維幾何 模板
幾何意義 向量的點積 a b a b a b cos cos 若cos cos 為正,兩向量之間的夾角為銳角 為負,兩向量夾角為鈍角 為量,兩向量夾角為直角。b在a方向上的投影 向量的叉積 a b a b a b sin sin 數值上表示a和b構成的平行四邊形的面積。include using n...