Added circle circle intersection area#139
Open
Chillee wants to merge 3 commits into
Open
Conversation
| 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); |
Member
There was a problem hiding this comment.
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); |
Member
There was a problem hiding this comment.
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); |
Member
There was a problem hiding this comment.
double is clearer than auto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No tests - sanity checked it.