模版 兩圓相交部分面積

2021-07-11 05:13:39 字數 1251 閱讀 4471

題目:

poj 2546 circular area

題意:

計算兩圓公共部分面積

//260k 0ms g++提交wa,c++提交ac o(╯□╰)o

#include

#include

#include

#include

#include

#include

using

namespace

std;

const

double eps=1e-8;

const

double pi=acos(-1.0);

struct circle;

double getdis(circle c1,circle c2)//計算圓心距

double calcarea(circle c1,circle c2)

else

if(c1.r>=c2.r+dis)else

if(c2.r>=c1.r+dis)

/*處理兩圓相交情況

分析交點及兩圓圓心組成的四邊形和交點與兩圓圓心組成的兩個扇形

假設c1圓扇形角為2*alpha,那麼四邊形的面積s等於:0.5*dis*c1.r*sin(alpha)*2=dis*c1.r*sin(alpha);

記c1,c2扇形面積分別為s1,s2.那麼s1=(2*alpha/(2*pi))*pi*c1.r*c1.r=alpha*c1.r*c1.r;

而且alpha可以用餘弦定理計算出來:cos(alpha)=(d^2+c1.r^2-c2.r^2)/(2*d*c1.r);

同理也可以計算出s2,所以相交部分面積為:s1+s2-s.

*/double angle1=acos((dis*dis+c1.r*c1.r-c2.r*c2.r)/(2*dis*c1.r));

double s1=angle1*c1.r*c1.r; //c1圓扇形面積

double s=dis*c1.r*sin(angle1); //四邊形面積

double angle2=acos((dis*dis+c2.r*c2.r-c1.r*c1.r)/(2*dis*c2.r)); //c2圓扇形面積

double s2=angle2*c2.r*c2.r;

return s1+s2-s;

}int main()

return

0;}

兩圓相交求相交面積

1.海 式 2.余弦公式cosa public double areaofintersectionofcircles int firstx,int firsty,int firstr,int secondx,int secondy,int secondr alpha math.acos d d fi...

HDU 3264 求兩圓相交的面積

此題意很簡單,思路也容易想到。但是我就是卡在了求兩圓相交求面積的地方。還好現在有了模板了。不說了,直接貼 還得多多總結,二分真的很好用,要學會用啊!include include include includeusing namespace std define inf 2147483647 def...

求兩圓是否相交

呃.貌似 是很簡單 今天課間休息 照了張相片用q發給爸爸了 另作上傳頭像用 這個實訓第五天了 從第一天helloworld 講到遞迴 呵呵 慢慢來 剛好複習 我們也要求每天寫日誌 我突然想起csdn 也來寫寫 只是隨便寫寫 別砸我 沒人看就算了 有人看就算了 先每天都寫了好多個 隨便來乙個 類cir...