I'm interested in maximising the area of intersection between two or more geometric regions (for now, in 2D). For instance, I can calculate the offset between the centres of two annuli with given radii and widths that maximises the area of intersection between the annuli:

kfup = 10; kfdn = 5; ω = 3.5; 
q1[offset_] := {0, offset (kfup - kfdn)};
upwidth = ω/kfup; dnwidth = ω/kfdn;
regions = {ImplicitRegion[ kfdn^2 < ({x, y}).({x, y}) < (kfdn + dnwidth)^2, {{x, -2 kfup, 2 kfup}, {y, -2 kfup, 2 kfup}}], 
ImplicitRegion[ kfup^2 < (-{x, y} + q1[offset]).(-{x, y} + q1[offset]) < (kfup + upwidth)^2, {{x, -2 kfup, 2 kfup}, {y, -2 kfup, 2 kfup}}]};
{time, {intersection, val}} = FindMaximum[RegionMeasure[RegionIntersection[regions]]
, {offset, 1.0, 1.1}] // AbsoluteTiming

However, this code runs quite slowly on my machine:

{13.0212, {2.41396, {offset -> 1.00885}}}

Is there a way to speed up this process, so that I can go on to maximise the intersection of more complicated regions? I'd eventually like to look at the intersection of four or more regions, which using the method above isn't feasible. I've been unable to parallelise this method, so any answers which show a way to parallelise it, or any answers giving completely different approaches to the problem, would be welcome. I'm using v11.0.0.


The above timing data is using the code included above. However, if I change the definition of the function q1 to

q1[offset_?NumericQ] := {0, offset (kfup - kfdn)};

the FindMaximum is no longer able to converge the optimisation. I don't understand this behaviour, as the RegionMeasure[RegionIntersection[regions]] should include only numeric expressions. Perhaps this is connected to the slow evaluation?

  • $\begingroup$ Your code fails for me. $\endgroup$
    – Feyre
    Commented Sep 5, 2016 at 12:38
  • $\begingroup$ @Feyre hopefully fixed $\endgroup$ Commented Sep 5, 2016 at 12:52
  • $\begingroup$ That's really a long time, unless you're working with an old computer there might be something other than the code going on. $\endgroup$
    – Feyre
    Commented Sep 5, 2016 at 13:36
  • $\begingroup$ I'm using a fairly quick computer: but if it runs considerably quicker elsewhere that would be interesting to know. Also, the previous failing code was due to the inclusion of a ?NumericQ in one of the functions, which surprises me; see edit. $\endgroup$ Commented Sep 5, 2016 at 14:06
  • $\begingroup$ Well, it takes me less than a second. $\endgroup$
    – Feyre
    Commented Sep 5, 2016 at 14:09

1 Answer 1


This seems to be an issue with symbolic evaluation. When I run your code in Mathematica 11, I get the following message:

Message[RegionMeasure::nmet, RegionIntersection[ImplicitRegion[25 < x^2 + y^2 < 32.49 && -20 <= x <= 20 && -20 <= y <= 20, {x, y}], ImplicitRegion[100 < x^2 + (5*offset - y)^2 < 107.12249999999999 && -20 <= x <= 20 && -20 <= y <= 20, {x, y}]]]

As you can see Mathematica tries to evaluate the expression symbolically inserting offset in the expression. You can avoid that by defining

regMeasure[offset_?NumericQ] := RegionMeasure[RegionIntersection[regions]]

and then evaluating

{time, {intersection, val}} = 
FindMaximum[regMeasure[offset], {offset, 1.0, 1.1}] // AbsoluteTiming

Regarding the difference to Mathematica 10.4: My guess is that Mathematica 10.4 defaults quickly to using Method->"NIntegrate" for RegionMeasure and suppresses the Warning Message. You can see that by forcing Method->"NIntegrate" for RegionMeasure like

regMeasure[offset_?NumericQ] :=
RegionMeasure[RegionIntersection[regions], Method -> "NIntegrate"];
{time, {intersection, val}} = 
FindMaximum[regMeasure[offset], {offset, 1.0, 1.1}] // AbsoluteTiming

which should take approximately the same time as the computation in Mathematica 10.4.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.