Skip to content

Conversation

Chillee
Copy link
Collaborator

@Chillee Chillee commented Nov 3, 2019

No tests - sanity checked it.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the epsilons now means that r < h can happen due to numerical precision, I suspect (though I haven't tested). h = min(h, r); may be reasonable? h < 0 can likely also happen but doesn't seem like a problem.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these inequalities can be simplified now without the epsilons

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double is clearer than auto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants