計算幾何 圓 二維模板

2021-07-01 19:25:58 字數 1094 閱讀 6002

#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(double x)

//兩圓求公切線

//a[i] 為第i條切線與圓a的交點

int get_tangents(circle a, circle b, pnode *a, pnode *b)

double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); //圓心距

double rdiff = a.r - b.r; //兩圓半徑差

double rsum = a.r + b.r; //兩圓半徑和

if(dcmp(d - rdiff) < 0)

return 0; //1.內含

double base = atan2(b.y - a.y, b.x - a.x); //向量ab的極角

if(dcmp(d) == 0) return -1; //2.重合

if(dcmp(d - rdiff) == 0)

double ang = acos((a.r - b.r) / d);

a[cnt] = a.point(base + ang); b[cnt] = b.point(base + ang); cnt++; //4.相交(外切、外離的外公切線也在此求出)

a[cnt] = a.point(base - ang); b[cnt] = b.point(base - ang); cnt++; //兩條外公切線的切點

if(dcmp(d - rsum) == 0)

else if(dcmp(d - rsum) > 0)

return cnt;

}int main()

二維計算幾何模板 圓

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

二維計算幾何模板(點,線)

include include include include include include include include include include include define e exp 1.0 define mod 1000000007 define inf 0x7fffffff d...