-
Notifications
You must be signed in to change notification settings - Fork 811
Added circle circle intersection area #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Author: Takanori MAEHARA, chilli | ||
* Date: 2019-11-03 | ||
* License: CC0 | ||
* Source: https://github.com/spaghetti-source/algorithm/blob/master/geometry/_geom.cc#L729 | ||
* Description: Calculates the area of the intersection of 2 circles | ||
* Status: | ||
*/ | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
}; | ||
auto l = (c - d).dist(), a = (l*l + cr*cr - dr*dr)/(2*l); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these inequalities can be simplified now without the epsilons |
||
else return A(cr, a) + M_PI*dr*dr - A(dr, a-l); | ||
} | ||
Chillee marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.