Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

6 Answers 6

up vote 20 down vote accepted

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

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

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.

share|improve this answer
2  
The scaling factor is 1/GoldenRatio^2. –  KennyColnago Oct 24 '12 at 17:48
    
@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. :) –  jVincent Oct 24 '12 at 19:39
    
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}]]}] –  chyaong Nov 8 '12 at 7:08

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]}]
share|improve this answer
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}]}
share|improve this answer
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}]]}]
share|improve this answer
    
Welcome to the Mathematica StackExchange. I recommend that you register your account so that you can easily keep track of answers, comments and questions you might post. I also recommend using the automatic image uploader available here when answering graphics questions! –  tkott Nov 9 '12 at 15:44

Also:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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