#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define e exp(1.0);
#define mod 1000000007
#define inf 0x7fffffff
#define inf 0x3f3f3f3f
typedef
long
long ll;
using
namespace
std;
#define zero(x) (((x)>0?(x):(-x))const
double eps=1e-8;
const
double pi=acos(-1.0);
int cmp(double x)
inline
double sqr(double x)
struct point;
point(double a,double b):x(a),y(b){};
void input()
friend point operator + (const point &a,const point &b)
friend point operator - (const point &a,const point &b)
friend
bool
operator == (const point &a,const point &b)
friend point operator * (const point &a,const
double &b)
friend point operator * (const
double &a,const point &b)
friend point operator / (const point &a,const
double &b)
double norm()
};//計算兩個向量的叉積
double det(const point &a,const point &b)
//計算兩個點的點積
double dot(const point &a,const point &b)
//計算兩個點的距離
double dist(const point &a,const point &b)
//op沿遠點逆時針旋轉角度a
point rotate_point(const point &p,double a)
//判斷數k的符號 -1負數 1正數 0零
int dcmp(double k)
double cross(const point &a,const point &b)
double
abs(const point &o)
struct line;
line(point x,point y):a(x),b(y){};
};//兩個點生成乙個線段/直線
line point_make_pair(const point a,const point b)
//p點到線段st的垂足,儲存在cp裡
void pointprojline(const point p,const point s,const point t,point &cp)
bool pointonsegment(point p,point s,point t)
//判斷線段a,b是否平行
bool parallel(line a,line b)
//判斷a,b是否相交,交點儲存在res
bool line_make_point(line a,line b,point &res)
//將線段a沿法向量平移len的線段
line move_d(line a,const
double &len)
//p0p1 x p0p2
double xmult(point p0,point p1,point p2)
double xmult(double x1,double y1,double x2,double y2,double x0,double y0)
//dot(p1-p0).(p2-p0)
double dmult(point p1,point p2,point p0)
double dmult(double x1,double y1,double x2,double y2,double x0,double y0)
//判斷3點是否共線
bool dots_inline(point p1,point p2,point p3)
bool dot_online_in(point p,line l)
bool same_side(point p1,point p2,line l)
bool opposite_side(point p1,point p2,line l)
//點關於直線的對稱點
point symmetric_point(point p1,point l1,point l2)
else
return ret;
}//判斷兩線段相交,包括端點和部分重合
bool intersect_in(line u,line v)
//判斷兩線段相交,不包括端點和部分重合
bool intersect_ex(line u,line v)
//判斷直線l1和線段l2是否相交
bool seg_inter_line(line l1,line l2)
//p點到線段st的距離
double dis_point_segment(const point p,const point s,const point t)
//p點到直線st的距離
double disptoline(point p,line l)
const
int maxn=1000;
struct polygon;
//多邊形的周長
double perimeter()
//多邊形的面積
double area()
//判斷點是否在多邊形內,0多邊形外,1多邊形內,2邊界上
int point_in(point t)
return num!=0;
}};struct circle
return dcmp(p.y-o.p.y)==-1;
}bool
operator == (const circle &o) const
};/*************************************/
int main()
計算幾何 二維幾何 模板
幾何意義 向量的點積 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...
計算幾何 圓 二維模板
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...