Mathematica Asked by Machinato on February 15, 2021
The question of finding the area of intwrsection of two regions with parameters has been answered here using and RegionIntersection
with delimeter GenerateConditions -> All
. More sophisticated example, for which Mathematica does not return any answer, is as follows.
Consider a vertices of a regular pentagon
regulPen[i_] := {Cos[-((2 [Pi])/5) + (2 [Pi])/5 i], Sin[-((2 [Pi])/5) + (2 [Pi])/5 i]};
We now rotate this pentagon by $pi/5$, forming a new pentagon with vertices
regulPenShif[i_] := {Cos[-([Pi]/5) + (2 [Pi])/5 i], Sin[-([Pi]/5) + (2 [Pi])/5 i]};
The area of intersection of these pentagons is $frac12 sqrt{frac52(5+sqrt{5})}$, which is confirmed by Mathematica. Now we shift the center of the second pentagon into the point ${p,q}$, the area of intersection should now depend on ${p,q}$, however
Area[RegionIntersection[
Polygon[{regulPen[1],
regulPen[2],
regulPen[3],
regulPen[4],
regulPen[5]}],
Polygon[{regulPenShif[1] + {p, q},
regulPenShif[2] + {p, q},
regulPenShif[3] + {p, q},
regulPenShif[4] + {p, q},
regulPenShif[5] + {p, q}}]],
GenerateConditions -> All]
returns itself. How to refine the code such that Mathematica will solve that indeed?
You can't get an exact symbolic area of the intersection of two regular pentagons with parameters when the parameters are symbolic because Area
is a computational function like NIntegrate
and not symbolic expression manipulator like Integrate
. Even the result you show isn't symbolic; it is just exact.
The best we can do is define a numeric evaluator for the area of the intersection. Like so:
regulPen[i_] := {Cos[-((2 π)/5) + (2 π)/5 i], Sin[-((2 π)/5) + (2 π)/5 i]}
regulPenShif[i_] := {Cos[-(π/5) + (2 π)/5 i], Sin[-(π/5) + (2 π)/5 i]}
area[{p_?NumericQ, q_?NumericQ}] :=
With[
{poly =
Polygon[{regulPen[1], regulPen[2], regulPen[3], regulPen[4], regulPen[5]}]},
area[{p_?NumericQ, q_?NumericQ}] :=
N @
Area[
RegionIntersection[
poly,
Polygon[
{regulPenShif[1] + {p, q}, regulPenShif[2] + {p, q},
regulPenShif[3] + {p, q}, regulPenShif[4] + {p, q},
regulPenShif[5] + {p, q}}]]]]
Then we can make a demonstration allowing us to see one the pentagons shifting around while the area of intersection is computed. Like so:
With[
{poly =
Polygon[{regulPen[1], regulPen[2], regulPen[3], regulPen[4], regulPen[5]}],
spacer = Invisible["mmmmmmmmmmmm"]},
Manipulate[
Column[
{Graphics[
{EdgeForm[Black], FaceForm[],
poly,
Polygon[
{regulPenShif[1] + pq, regulPenShif[2] + pq, regulPenShif[3] + pq,
regulPenShif[4] + pq, regulPenShif[5] + pq}]},
ImageSize -> Medium],
Style[Row[{"Shift: ", pq, " Area: ", area[pq]}], "SR"]},
Center],
{{pq, {0, 0}, Style[Row[{spacer, "Shift "}], 16]}, {-1, -1}, {1, 1}, {.05, .05},
ImageSize -> {175, 175}},
ControlPlacement -> Bottom]]
Answered by m_goldberg on February 15, 2021
Your code works for concrete p,q
in 12.2, e.g.
p = -1/4; q = 1/2; Area[RegionIntersection[Polygon[{regulPen[1], regulPen[2],
regulPen[3], regulPen[4],regulPen[5]}],Polygon[{regulPenShif[1] + {p, q}, regulPenShif[2] +{p, q},
regulPenShif[3] + {p, q}, regulPenShif[4] +{p, q}, regulPenShif[5] + {p, q}}]]]
1/2 (1/4 (1 - Sqrt[5]) ((Sqrt[5 + Sqrt[5]] (-4 Sqrt[2] + Sqrt[10]))/( 4 (-5 + Sqrt[5])) + 1/4 (2 - Sqrt[2 (5 + Sqrt[5])]) +..
, but a long output is not very useful.
Answered by user64494 on February 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP