3
$\begingroup$

In the way to find the maximum intersection between a triangle region and a disk region I made a short script which reads

Clear[intArea]
intArea[x0_?NumberQ, y0_?NumberQ] := 
 Module[{rcir, R, l1, l2, l3, rtri, r = 2, x, y},
  l1 = -4 y;
  l2 = 2 Sqrt[3] (-4 + x) + 2 y;
  l3 = -2 Sqrt[3] (-2 + x) + 2 (-2 Sqrt[3] + y);
  rtri = ImplicitRegion[l1 <= 0 && l2 <= 0 && l3 <= 0, {x, y}];
  rcir = Disk[{x0, y0}, r];
  R = RegionIntersection[rtri, rcir];
  Return[Area[DiscretizeRegion[R]]]
  ]

NMaximize[{intArea[x0, y0], 0. < x0 < 5., 0. < y0 < 5.}, {x0, y0}, Method -> "DifferentialEvolution"]

but something is not according to the rules. I would appreciate to receive some help. Thanks.

$\endgroup$

2 Answers 2

4
$\begingroup$

Edit

  • To simplify the code, we use Triangle.

  • For a fixed triangle tri = SSSTriangle[4, 4, 4];, we moving a disk with radius 2 and find the maximum area in tri.

  • To faster the code we use f[{x_?NumericQ, y_?NumericQ}] instead of f[x_?NumericQ, y_?NumericQ],but I don't know why such setting could make the code faster.( I finally remove the BoundaryDiscreteRegion)

Clear["Global`*"];
tri = SSSTriangle[4, 4, 4];
r = 2;
intersection[{x_?NumericQ, y_?NumericQ}] := 
  RegionIntersection[Disk[{x, y}, 2], tri];
area[{x_?NumericQ, y_?NumericQ}] := intersection[{x, y}] // Area;
sol = NMaximize[{area[{x, y}]}, {x, y}]
Graphics[{tri, EdgeForm[Cyan], FaceForm[], Disk[{x, y}, 2] /. sol[[2]],
   FaceForm[Red], 
  BoundaryDiscretizeRegion@intersection[{x, y} /. sol[[2]]], 
  AbsolutePointSize[8], Point[{x, y}] /. sol[[2]]}]

{6.75943, {x -> 2., y -> 1.1547}}

enter image description here

  • Use BoundaryDiscretizeGraphics make the code faster but could not get the exact center coordinate.
Clear["Global`*"];
tri = SSSTriangle[4, 4, 4];
r = 2;
intersection[{x_?NumericQ, y_?NumericQ}] := 
  RegionIntersection[BoundaryDiscretizeGraphics@Disk[{x, y}, 2], tri];
area[{x_?NumericQ, y_?NumericQ}] := intersection[{x, y}] // Area;
sol = NMaximize[{area[{x, y}]}, {x, y}]
Graphics[{tri, EdgeForm[Cyan], FaceForm[], Disk[{x, y}, 2], 
   FaceForm[Red], intersection[{x, y}], AbsolutePointSize[8], 
   Point[{x, y}]} /. sol[[2]]]

{6.75549, {x -> 1.99646, y -> 1.15402}}

Original

  • BoundaryDiscretizeRegion before RegionIntersection.
Clear["Global`*"]; 
intArea[x0_?NumberQ, y0_?NumberQ] := 
 Module[{rcir, R, l1, l2, l3, rtri, r = 2, x, y}, l1 = -4 y;
  l2 = 2 Sqrt[3] (-4 + x) + 2 y;
  l3 = -2 Sqrt[3] (-2 + x) + 2 (-2 Sqrt[3] + y);
  rtri = 
   RegionPlot[
    l1 <= 0 && l2 <= 0 && l3 <= 0, {x, -10, 10}, {y, -10, 10}];
  rcir = Disk[{x0, y0}, r];
  R = RegionIntersection[BoundaryDiscretizeGraphics@rtri, 
    BoundaryDiscretizeGraphics@rcir];
  Return[Area[R]]]
NMaximize[{intArea[x0, y0], 0. < x0 < 5., 0. < y0 < 5.}, {x0, y0}]

{6.74374, {x0 -> 1.99878, y0 -> 1.15581}}

$\endgroup$
3
  • $\begingroup$ Thanks for the help! It happens that the maximization process is quite delayed. Any hint about how to improve the maximization? $\endgroup$ Commented Apr 12 at 14:02
  • $\begingroup$ @Cesareo I don't understand the original question ,maybe you could describe it in detail? $\endgroup$ Commented Apr 12 at 14:30
  • $\begingroup$ Your answer attends perfectly the question purpose. Regarding quick computations I think is better to submit another question. Thanks again! $\endgroup$ Commented Apr 12 at 18:19
1
$\begingroup$

Using equilateral triangle with circumcentre: {0,0}

RegionPlot[
 2 + Sqrt[3] y >= 0 && 3 x + Sqrt[3] y <= 4 && 
  Sqrt[3] y <= 4 + 3 x, {x, -4, 4}, {y, -4, 4}]

enter image description here

Defining intersection using Boolean operation:

ir[a_, b_] := 
 ImplicitRegion[
  2 + Sqrt[3] y >= 0 && 3 x + Sqrt[3] y <= 4 && 
   Sqrt[3] y <= 4 + 3 x && (x - a)^2 + (y - b)^2 <= 4, {{x, -5, 
    5}, {y, -5, 5}}]

Area for centres of circle:

ListPlot3D[{#[[1]], #[[2]], Area[ir[#[[1]], #[[2]]]]} & /@ 
  Tuples[Range[-2, 2, 0.1], 2]]

enter image description here

Using interpolation to estimate maximum area (and comparing to expected area by symmetry:

pts = {{#[[1]], #[[2]]}, ar[#[[1]], #[[2]]]} & /@ 
   Tuples[Range[-2, 2, 0.1], 2];
int = Interpolation[pts]
NMaximize[{int[u, v], -2 < u < 2, -2 < v < 2}, {u, v}]
ar[0, 0]
Area[ir[0, 0]] // N
Plot3D[int[u, v], {u, -2, 2}, {v, -2, 2}]

enter image description here

Finer grid takes longer:

pts2 = {{#[[1]], #[[2]]}, ar[#[[1]], #[[2]]]} & /@ 
   Tuples[Range[-2, 2, 0.05], 2];
int2 = Interpolation[pts2]
NMaximize[{int2[u, v], -2 < u < 2, -2 < v < 2}, {u, v}]
Plot3D[int2[u, v], {u, -2, 2}, {v, -2, 2}]

enter image description here

func[u_, v_] := 
 Module[{reg = ir[u, v]}, 
  RegionPlot[reg, PlotRange -> {{-2, 2}, {-2.5, 2.5}}, 
   Prolog -> {Opacity[0.5], Yellow, 
     Triangle[4 Sqrt[3]/3 CirclePoints[3]], Red, Circle[{u, v}, 2], 
     Blue, Point[{u, v}]}, PlotLabel -> N@Area[reg], AspectRatio -> Automatic]]

func[0,0]:

enter image description here

$\endgroup$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.