13
$\begingroup$

This is my code:

Graphics[{EdgeForm[Yellow], Yellow, Polygon[Table[{Cos[t], Sin[t]}, {t, 0, 4 π, (4 π)/5}]]}]

which gives this:

but I want to get:

enter image description here

How?

$\endgroup$
  • $\begingroup$ In Version 11, your code gives the second image. ($CloudVersion: 1.42.1 (June 5, 2017)) $\endgroup$ – kglr Jun 27 '17 at 5:18
21
$\begingroup$

You could use the undocumented functions SimplePolygonPartition and PolygonCombine:

poly = Polygon[Table[{Cos[t], Sin[t]}, {t, 0, 4 \[Pi], (4 \[Pi])/5}]];

Graphics`Mesh`MeshInit[];
poly2 = PolygonCombine@SimplePolygonPartition@poly;
Graphics[{EdgeForm[Black], Yellow, poly2}]

enter image description here

$\endgroup$
  • $\begingroup$ Now this is the kind of answer I was hoping for. +1 $\endgroup$ – Rojo Oct 24 '12 at 18:27
  • $\begingroup$ Does this also work for 3D polygons? Just tried without success - seems to strip off any surplus dimensions. $\endgroup$ – Yves Klett Jan 28 '13 at 9:07
  • $\begingroup$ @YvesKlett, I think you've answered your own question :-) $\endgroup$ – Simon Woods Jan 28 '13 at 13:51
  • 1
    $\begingroup$ Ach, I hate being right sometimes. $\endgroup$ – Yves Klett Jan 28 '13 at 13:52
8
$\begingroup$

The problem is that you have overlapping areas. The way this is handled by Mathematica is twice covered it will be negated and not be filled.

You could draw it by creating both the points at the tips and the valleys:

 Graphics[{Yellow,
 Polygon[
 Reverse@Riffle[
   Table[{Cos[t], Sin[t]}, {t, 0, 2 π, (2 π)/5}],
   Table[
    2/(3 + Sqrt[5]) {Cos[t + π/5], Sin[t + π/5]}, {t, 0, 
    2 π, (2 π)/5}]
   ]]
  }]

I'm not certain about the scaling factor for the valleys, but it looks close enough.

$\endgroup$
  • 2
    $\begingroup$ The scaling factor is 1/GoldenRatio^2. $\endgroup$ – KennyColnago Oct 24 '12 at 17:48
  • $\begingroup$ @KennyColnago Ah yes, so it's 2/(3+Sqrt[5]). I was lazy and had something in the back of my mind telling me it was something with sqrt and 3. So close, yet so far. :) $\endgroup$ – jVincent Oct 24 '12 at 19:39
  • $\begingroup$ Graphics[{Yellow, Polygon[Join @@ Table[{{Cos[t], Sin[t]}, 1/2 (3 - Sqrt[5]) {Cos[t + π/5], Sin[t + π/5]}}, {t, 0, 2 π, (2 π)/5}]]}] $\endgroup$ – chyanog Nov 8 '12 at 7:08
4
$\begingroup$

In Mathematica 12

poly=Polygon[Table[{Cos[t],Sin[t]},{t,0,4π, 4π/5}]];
Graphics[{Yellow,#},PlotRange->1]& /@ {poly,OuterPolygon[poly],InnerPolygon[poly]}

enter image description here

$\endgroup$
3
$\begingroup$

You could also fill it with a disk. I'm hoping for a less manual answer anyway

Graphics[{Yellow, 
  Polygon[Table[{Cos[t], Sin[t]}, {t, 0, 4 \[Pi], (4 \[Pi])/5}]], 
  Disk[{0, 0}, 1/GoldenRatio^2]}]
$\endgroup$
3
$\begingroup$
Graphics@Polygon@Array[{Sin@#,Cos@#}&[π/5#]If[OddQ@#,3-√5,2]/2&,10] 

Graphics@Polygon@Table[(1-(√5 - 1)/2*Mod[i, 2])*{Cos[π/5i], Sin[π/5i], {i,0,9}]}

Graphics[{Yellow, 
  Polygon[Table[{Sin[t], Cos[t]}, {t, 0, 4 π, (4 π)/5}]], 
  Polygon[Table[1/2 (3 - Sqrt[5]) {Sin[t + Pi/5], Cos[t + Pi/5]},
{t, 0, 2 π, (2 π)/5}]]}]
$\endgroup$
1
$\begingroup$

Also:

 ListLinePlot[Table[{Cos@i, Sin@i}, {i, 0, 4 \[Pi], 4 \[Pi]/5}],
     PlotStyle -> None, Axes -> None, Filling -> 0, AspectRatio -> 1, 
     FillingStyle -> Yellow]
$\endgroup$
  • $\begingroup$ Nice example. +1 $\endgroup$ – Mr.Wizard Jan 24 '13 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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