4
$\begingroup$

I have this code that generates the image below, my question is how to calculate the area and perimeter of the first figure and all the variations of it considering a side of square "L" or as possible. The figure shows some variations, I imagine that MMA can find others. Help me with more code, still very new to MMA

pts = RandomReal[{0, 1}, {20000, 2}];
pts = Select[pts, 
And @@ Table[
  Norm[# - p] < 1, {p, {{0, 0}, {1, 0}, {1, 1}, {0, 1}}}] &];
Graphics[{Thick, Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}], 
Circle[{0, 0}, 1, {0, Pi/2}], Circle[{1, 0}, 1, {Pi/2, Pi}], 
Circle[{1, 1}, 1, {Pi, 3 Pi/2}], Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}], 
PointSize[Small], Point[pts]}]

EDIT : The idea is to have a variety of areas to calculate by hand after (they are challenges but I need to check them) Below were some that I had not noticed, that is the grace of MMA

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Hi. I find it difficult to understand your question, in particular I do not understand "...all the variations of it considering a side of square "L" or as possible." I'd suggest you edit the question to make it clearer. $\endgroup$
    – user293787
    Jul 16, 2022 at 5:42
  • $\begingroup$ Hello, look at the edition above $\endgroup$
    – Nabla
    Jul 17, 2022 at 4:09

2 Answers 2

4
$\begingroup$

All the arc lengths are equal to Pi/6. For example,

arc = RegionIntersection[Circle[{0, 0}, 1, {0, Pi/2}], 
   Disk[{1, 0}, 1, {Pi/2, Pi}], Disk[{0, 1}, 1, {3 Pi/2, 2 Pi}]];
Show[Graphics[{Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}], 
   Circle[{0, 0}, 1, {0, Pi/2}], Circle[{1, 0}, 1, {Pi/2, Pi}], 
   Circle[{1, 1}, 1, {Pi, 3 Pi/2}], 
   Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}]}], 
 Region[Style[arc, Directive[Thick, Red]]]]
arc // ArcLength

enter image description here

π/6

And we can calculate the areas at the same way. For example the center area.

reg = RegionIntersection[Disk[{0, 0}, 1, {0, Pi/2}], 
   Disk[{1, 0}, 1, {Pi/2, Pi}], Disk[{1, 1}, 1, {Pi, 3 Pi/2}], 
   Disk[{0, 1}, 1, {3 Pi/2, 2 Pi}]];
Show[Graphics[{Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}], 
   Circle[{0, 0}, 1, {0, Pi/2}], Circle[{1, 0}, 1, {Pi/2, Pi}], 
   Circle[{1, 1}, 1, {Pi, 3 Pi/2}], 
   Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}]}], Region[reg]]
reg // Area

enter image description here

1/3 (3 - 3 Sqrt[3] + π)

$\endgroup$
1
  • $\begingroup$ Thanks for answering, how do you calculate for other more complicated ones, how do you know which parameters to choose? $\endgroup$
    – Nabla
    Jul 17, 2022 at 4:04
4
$\begingroup$
{centers,arcs}={{{0,0},{1,0},{1,1},{0,1}},{{0,1/2},{1/2,1},{1,3/2},{3/2,2}}Pi};

Length[ineqs=Simplify@CylindricalDecomposition[0<x<1&&0<y<1&&
  !(Or@@(#.#==1&[{x,y}-#]&/@centers)),{x,y},"Components"]]

impRegs=ImplicitRegion[#,{{x,0,1},{y,0,1}}]&/@ineqs;

regs=BoundaryDiscretizeRegion/@impRegs;

Length[gb=GatherBy[Thread[{RegionUnion/@Rest@Subsets[regs],
  Round[Total/@Rest@Subsets[Area/@impRegs],10^-12.]}],Last]]//AbsoluteTiming

ans=SortBy[gb[[All,1,1]],Area];

Show[#,Graphics[{EdgeForm[Black],FaceForm[],Rectangle[],MapThread[Circle[#,1,#2]&,
  {centers,arcs}]}],ImageSize->85,PlotRange->{{-0.1,1.1},{-0.1,1.1}},
  PlotLabel -> ({#, NumberForm[#2, {16, 3}]} & @@@ {{"A", Area@#}, {"P", Perimeter@#}})
]&/@ans

![enter image description here

The previous answer:

{centers,arcs}={{{0,0},{1,0},{1,1},{0,1}},{{0,Pi/2},{Pi/2,Pi},{Pi,(3 Pi)/2},{(3 Pi)/2,2 Pi}}};
regs=BoundaryDiscretizeGraphics[Disk[#],PlotRange->{{0,1},{0,1}}]&/@centers;
ineqs=#.#<1&[{x,y}-#]&/@centers;
ops={And,Or,Xor,#&&!#2&};

gb=GatherBy[Thread[{Groupings[regs,Thread[Function[o,BooleanRegion[o,{##}]&]/@ops->2],Hold],
  Reduce[#&&0<x<1&&0<y<1,{x,y}]&/@Groupings[ineqs,Thread[ops->2]]}],Last];//AbsoluteTiming

Length[ans=SortBy[DeleteDuplicatesBy[Select[ReleaseHold[gb[[All,1,1]]],Area[#]>0&],
  Round[Area@#,10^-4.]&],Area]]

Show[#,Graphics[{EdgeForm[Black],FaceForm[],Rectangle[],
  MapThread[Circle[#,1,#2]&,{centers,arcs}]}],ImageSize->100,
  PlotRange->{{-0.1,1.1},{-0.1,1.1}}]&/@ans
$\endgroup$
3
  • $\begingroup$ Thanks for responding, I was amazed how MMA with the correct orders does what you ask. 3 things 1) Could you explain the code a little to understand it better? 2) It is possible to determine the area and perimeter of each one as well as a table that is to say Figure, Perimeter, Area 3) What is the difference between the first code and the second Thank you very much first of all $\endgroup$
    – Nabla
    Jul 17, 2022 at 4:02
  • $\begingroup$ When executing it I don't get numbers on the sides, I don't know why this happens. MMA version 12.0 $\endgroup$
    – Nabla
    Jul 17, 2022 at 4:12
  • $\begingroup$ hi, I have not reviewed everything, but at first glance the last one catches my attention, if we assume a square of side one by approximation the area is 1, but the perimeter comes out 13,.... Shouldn't it come out 4? $\endgroup$
    – Nabla
    Jul 18, 2022 at 22:38

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.