0
$\begingroup$

I have a difficulty to programmatically adjust the size of a polygon within an inset of a conic (here I limit myself to a circle) in order to have all its vertices on the circle:

a = {-2, 0}; b = {2, 0}; c = {Sqrt[2], Sqrt[2]}; d = {-Sqrt[2], Sqrt[
2]}; e = {0, 2}; f = {0, -2};    
ContourPlot[{x^2 + y^2 - 4 == 0}, {x, -2.5, 2.5}, {y, -2.5, 2.5}, 
ContourStyle -> {Blue, Thin}, Frame -> None, Axes -> True, 
AspectRatio -> 1, Epilog ->
 {
   {Blue, PointSize[0.02], Point[a],   
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"a", a})},
   {Blue, PointSize[0.02], Point [b],
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"b", b})},
   {Blue, PointSize[0.02], Point[c],
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"c", c})},
   {Blue, PointSize[0.02], Point[d],
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"d", d})},
   {Blue, PointSize[0.02], Point[e],
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"e", e})},
   {Blue, PointSize[0.02], Point[f],
    (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"f", f})},
   {Inset[Graphics[
    {ColorData["Legacy", "Banana"], EdgeForm[{Thick, Pink}], 
     Opacity[0.15], Polygon[{a, b, c, d}]}], {0, 0}, {0, 0}, 4.2]},
   {Inset[Graphics[
    {ColorData["Legacy", "SlateBlue"], EdgeForm[{Thick, Pink}], 
     Opacity[0.15], Polygon[{a, e, c, f}]}], {0, 0}, {0, 0}, 3.6]}
 }] 

Although the two polygons I defined here out of six points have coordinates that are on the circle, I need to adjust the size parameter of the Inset, for every different position of a set of four points.
By trial an error I achieved something but far from satisfactory: I need to include the code above in a notebook under development where all the points are on the conic and dynamic and the polygon is constructed in the Epilog with these points.
Is there a way with MMA to compute the value of the Inset size parameter according to the vertices coordinates?

$\endgroup$
4
  • $\begingroup$ Yeah, why can't you just use Show, with the insets as separate graphics. $\endgroup$
    – lalmei
    Commented Jun 9, 2014 at 16:55
  • $\begingroup$ Why do you need to use Inset[Graphics[... instead of Epilog->{Polygon[{a,b,c,d}]...? $\endgroup$
    – Kuba
    Commented Jun 9, 2014 at 19:42
  • $\begingroup$ @Kuba Correct! I didn't think about using {ColorData["Legacy", "Banana"], EdgeForm[{Thick, Pink}], Opacity[0.15], Polygon[{a, b, c, d}]} in the Epilog instead of Inset... to achieve the same result. Inset obviously here was a wrong option and I guess that finding correctly the right Size would have been challenging and futile. I consider your comment as an answer. $\endgroup$
    – Sigis K
    Commented Jun 9, 2014 at 21:19
  • $\begingroup$ @Kuba you should repost your comment as answer.. $\endgroup$
    – halmir
    Commented Jun 9, 2014 at 21:26

1 Answer 1

3
$\begingroup$

OK, here's shorter version:

a = {-2, 0}; b = {2, 0}; c = {Sqrt[2], Sqrt[2]}; d = {-Sqrt[2], Sqrt[2]}; e = {0, 2}; 
f = {0, -2};
ContourPlot[{x^2 + y^2 - 4 == 0}, {x, -2.5, 2.5}, {y, -2.5, 2.5}, Axes -> True,  
            ContourStyle -> {Blue, Thin}, Frame -> None, AspectRatio -> 1, 
            Epilog -> {
 {ColorData["Legacy", "Banana"], EdgeForm[{Thick, Pink}], Opacity[0.15], 
  Polygon[{a, b, c, d}], ColorData["Legacy", "SlateBlue"], Polygon[{a, e, c, f}]},
 Blue, [email protected], {Point@#2, Text[Style[#1, 18, Bold], 1.1 #2]} & @@@ {
  {"a", a}, {"b", b}, {"c", c}, {"d", d}, {"e", e}, {"f", f}}}]

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.

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