日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

两圆相交求面积 hdu5120

發(fā)布時(shí)間:2023/12/9 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 两圆相交求面积 hdu5120 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)載

?

兩圓相交分如下集中情況:相離、相切、相交、包含。

設(shè)兩圓圓心分別是O1和O2,半徑分別是r1和r2,設(shè)d為兩圓心距離。又因?yàn)閮蓤A有大有小,我們?cè)O(shè)較小的圓是O1。

相離相切的面積為零,代碼如下:

?

[cpp] view plaincopy print?
  • double?d?=?sqrt((a.x-b.x)*(a.x-b.x)?+?(a.y-b.y)*(a.y-b.y));??
  • if?(d?>=?r1+r2)??
  • ????return?0;??
  • double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); if (d >= r1+r2)return 0;

    包含的面積就是小圓的面積了,代碼如下:

    ?

    ?

    [cpp] view plaincopy print?
  • if(r2?-?r1?>=?d)??
  • ????return?pi*r1*r1;??
  • if(r2 - r1 >= d)return pi*r1*r1;

    接下來看看相交的情況。

    ?

    相交面積可以這樣算:扇形O1AB - △O1AB + 扇形O2AB - △O2AB,這兩個(gè)三角形組成了一個(gè)四邊形,可以用兩倍的△O1AO2求得,

    所以答案就是兩個(gè)扇形-兩倍的△O1AO2

    因?yàn)?/p>

    所以

    那么

    同理

    接下來是四邊形面積:

    代碼如下:

    ?

    double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d)); double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d)); return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);

    ?

    ?

    #include<iostream> #include<cmath> using namespace std;#define pi acos(-1.0)typedef struct node {int x;int y; }point;double AREA(point a, double r1, point b, double r2) {double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));if (d >= r1+r2)return 0;if (r1>r2){double tmp = r1;r1 = r2;r2 = tmp;}if(r2 - r1 >= d)return pi*r1*r1;double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1); }int main() {point a, b;a.x=2, a.y=2;b.x=7, b.y=2;double result = AREA(a, 3, b, 5);printf("%lf\n", result);return 0; }

    ?

    ?

    ?

    Intersection

    Time Limit: 4000/4000 MS (Java/Others)????Memory Limit: 512000/512000 K (Java/Others)
    Total Submission(s): 3443????Accepted Submission(s): 1302


    Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.


    A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.


    Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.

    ?

    Input The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

    Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.

    ?

    Output For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.

    ?

    Sample Input 2 2 3 0 0 0 0 2 3 0 0 5 0

    ?

    Sample Output Case #1: 15.707963 Case #2: 2.250778 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; double x1,ya,x2,y2,dis,s1,s2,s3,R,r; double sov(double R,double r){if(dis>=r+R) return 0;if(dis<=R-r) return acos(-1.0)*r*r;double x=(R*R-r*r+dis*dis)/2.0/dis;double y=(r*r-R*R+dis*dis)/2.0/dis;double seta1=2*acos(x/R);double seta2=2*acos(y/r);double ans=seta1*R*R/2.0+seta2*r*r/2.0;double h=sqrt(R*R-x*x);return ans-dis*h; } int main(){int tas=1,T;for(scanf("%d",&T);T--;){scanf("%lf%lf",&r,&R);scanf("%lf%lf%lf%lf",&x1,&ya,&x2,&y2);dis=sqrt((x1-x2)*(x1-x2)+(ya-y2)*(ya-y2));s1=sov(R,R),s2=sov(R,r),s3=sov(r,r);printf("Case #%d: %.6f\n",tas++,s1-2*s2+s3);} }

    ?

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/mfys/p/7622133.html

    總結(jié)

    以上是生活随笔為你收集整理的两圆相交求面积 hdu5120的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。