Skip to content

Commit

Permalink
responded to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chillee committed Nov 4, 2019
1 parent 5952d3e commit a03b73a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions content/geometry/CircleCircleArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

template<class P>
double circleCircleArea(P c, double cr, P d, double dr) {
if (cr < dr) swap(c, d), swap(cr, dr);
auto A = [&](double r, double h) {
return r*r*acos(h/r)-h*sqrt(r*r-h*h);
};
auto l = (c - d).dist(), a = (l*l + cr*cr - dr*dr)/(2*l);
if (sgn(l - cr - dr) >= 0) return 0; // far away
if (sgn(l - cr + dr) <= 0) return M_PI*dr*dr;
if (sgn(l - cr) >= 0) return A(cr, a) + A(dr, l-a);
else return A(cr, a) + M_PI*dr*dr - A(dr, a-l);
if (cr < dr) swap(c, d), swap(cr, dr);
auto A = [&](double r, double h) {
return r*r*acos(h/r)-h*sqrt(r*r-h*h);
};
auto l = (c - d).dist(), a = (l*l + cr*cr - dr*dr)/(2*l);
if (l - cr - dr >= 0) return 0; // far away
if (l - cr + dr <= 0) return M_PI*dr*dr;
if (l - cr >= 0) return A(cr, a) + A(dr, l-a);
else return A(cr, a) + M_PI*dr*dr - A(dr, a-l);
}

0 comments on commit a03b73a

Please sign in to comment.