二維計算幾何模板 圓

2021-07-17 02:07:41 字數 4414 閱讀 6162

#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 1000000007

#define inf 0x7fffffff

#define inf 0x3f3f3f3f

typedef

long

long ll;

using

namespace

std;

//基本函式

const

double eps=1e-8;

int cmp(double x)

const

double pi=acos(-1.0);

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 dis(const point &a,const point &b)

point rotate_point(const point &p,double a)

int dcmp(double k)

double cross(const point &a,const point &b)

double

abs(const point &o)

double mysqrt(double n)

/**************************************/

struct circle ;

circle(point p,double r):p(p),r(r){};

bool

operator

< (const circle &o) const

return dcmp(p.y-o.p.y)==-1;

}bool

operator == (const circle &o) const

};//判斷點是否在圓內 //誤差範圍內

bool point_in_circle(point a,circle p)

/****************************************/

//圓與多邊形的交面積

int pon; //多邊形的點數

point res[1000]; //逆/順時針多邊形的點

double r; //圓心在原點的圓的半徑

/***************************************/

//圓與線段/直線的交點

//交點ret,個數num

void circle_cross_line(point a,point b,circle c,point ret,int &num)

if(dcmp(t2-1)<=0&&dcmp(t2)>=0)

}else

if(dcmp(delta)==0)

}}point crosspt(const point &a,const point &b,const point &p,const point &q)

double sector_area(const point &a,const point &b)

double calc(const point &a,const point &b)

}else

else

else

return sector_area(a,b);}}

}//圓與多邊形的交面積

double circle_polygon_area()

}return

fabs(ret);

}/****************************************/

//兩個圓的交面積/幾個圓的並面積

/****************************************/

//兩個圓的交面積

double circle_area(circle x,circle y)

//圓的面積並。

circle tc[10]; //待求圓

int cm; //待求圓的個數

//向量p旋轉x角度後的向量,cost,sint為角度x的三角函式值

point rotate(const point &p,double cost,double sint)

//圓a,b的兩個交點

paircrosspoint(point ap,double ar,point bp,double br)

inline paircrosspoint(const circle &a,const circle &b)

struct node ;

bool

operator

<(const node &o)const

double solve()

}if(ok) c[n++]=tc[i];

}double ans=0;

for(int i=0; ivector

event;

point boundary=c[i].p+point(-c[i].r,0);

event.push_back(node(boundary,-pi,0));

event.push_back(node(boundary,pi,0));

for(int j=0; jif(i==j) continue;

double d=(c[i].p-c[j].p).norm();

if(dcmp(d-(c[i].r+c[j].r))<0) else }}

sort(event.begin(),event.end());

int sum=event[0].d;

for(int j=1; j<(int)event.size(); ++j)

sum+=event[j].d;}}

return ans;

}/****************************************/

//圓的覆蓋

point p[533]; //初始點

int pn; //初始點的個數

/****************************************/

//半徑為r的圓最大能覆蓋的點的個數 o(n^3)

point center1,center2;//根據兩個點確定的圓心

//根據兩個點,及半徑確定圓心(有兩個圓心)

void get_center_point(point a,point b,double r)

else

}int max_point_cover()

ans=max(ans,max(ans1,ans2));}}

return ans;

}//給出n個點,求最小覆蓋圓

void circle_center(point p0,point p1,point p2,point &cp)

void circle_center(point p0,point p1,point &cp)

circle min_circle_cover()}}

}}

}return temp;

}int main()

計算幾何 圓 二維模板

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

計算幾何 二維幾何 模板

幾何意義 向量的點積 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 include include include include include include define e exp 1.0 define mod 1000000007 define inf 0x7fffffff d...