Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5120
Problem Solving report: give you two exactly the same ring, asking you to ask how much area the two rings intersect?
Test instructions looked for a long time did not understand. The ring consists of a small circle inside a large circle, the middle part is the circle, the intersection area of the two rings = the area where the large circle intersects the area of the small Circle + the area where the small circle intersects the small circle.
In other words, this problem can be converted to two circle of the intersection of the area. can use two round equation, find out the intersection of the circle of the line, and then find the center of the distance to the line, you can find two circle corresponding to the sector of the central angle is how much. The point to note is that the position of the two circle may be intersected, contained, or absent, where the intersection of the case, but also note that the smaller circle of the fan central angle is not obtuse, can be judged by the position of the two center of the circle is the intersection of the same side of the line, Judging this can be two centers into a linear equation, the product is less than 0, indicating that the two points on both sides of the line. Then, if it is the center of the intersection of the line in the same side, then, the area of the intersection of this part of the time, you should use the area of the small circle sector plus the area of the triangle, or the sector area minus the Triangle area.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const DoublePI = ACOs (-1.0), EPS = 1e-9;8 struct Point9 {Ten Doublex, y; One }; A structCircle - { - Point C; the DoubleR; - }; - - Circle A,a,b,b; + DoubleDis (point a,point B) - { + returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); A } at DoubleDis_line (Point P,DoubleADoubleBDoublec) - { - return(Fabs (A*p.x+b*p.y+c)/sqrt (a*a+b*b)); - } - DoubleGet_in (Circle X,circle y)//find the area of intersection of two gardens - { in if(Dis (X.C,Y.C) < (X.R-Y.R) | | fabs (DIS (x.c,y.c)-(X.R-Y.R)) < EPS)returnPI * y.r*Y.R; - if(Dis (X.C,Y.C) > X.R+Y.R | | fabs (DIS (x.c,y.c)-(X.R+Y.R)) < EPS)return 0; to DoubleA =2.0* (x.c.x-y.c.x), B =2.0* (X.C.Y-Y.C.Y), C = y.c.x*y.c.x-x.c.x*x.c.x + y.c.y*y.c.y-x.c.y*x.c.y+x.r*x.r-y.r*Y.R; + DoubleL1 =Dis_line (x.c,a,b,c); - DoubleCo1 = ACOs (L1/X.R) *2.0; the DoubleS1 = PI * x.r*x.r* (co1/pi/2.0) - (0.5*x.r*x.r*sin (co1)); * DoubleL2 =Dis_line (y.c,a,b,c); $ DoubleCO2 = ACOs (L2/Y.R) *2.0, S2;Panax Notoginseng if((a*x.c.x+b*x.c.y+c) * (a*y.c.x+b*y.c.y+c) <=0)//Two center on both sides of the garden intersection -S2 = PI * y.r*y.r* (co2/pi/2.0) - (0.5*y.r*y.r*sin (CO2)); the ElseS2 = PI * y.r*y.r* (2.0*PI-CO2)/(2.0*PI)) + (0.5*y.r*y.r*sin (CO2)); + returns1+S2; A } the + - intMain () $ { $ //freopen ("in", "R", stdin); - intT,kase =1; -scanf"%d",&T); the while(t--) - {Wuyi Doubler1,r2; thescanf"%LF%LF",&r1,&r2); -scanf"%LF%LF",&a.c.x,&a.c.y); WuA =A; -scanf"%LF%LF",&b.c.x,&b.c.y); Aboutb =B; $A.R = B.R =R2; -A.R = B.R =R1; - DoubleAns =get_in (A, b); - //printf ("%lf\n", Get_in (A, b)); AAns-= (2.0*get_in (A, b)); + //printf ("%lf\n", Get_in (A, b)); theAns + =get_in (A, b); - //printf ("%lf\n", Get_in (A, b)); $printf"Case #%d:%lf\n", kase++,ans+EPS); the } the return 0; the}
View Code
HDU 5120 intersection (2014 Beijing) (Field I problem calculation geometry)