3
$\begingroup$

I have a (vaguely) complex curve with some self-intersections, and I would like to add a filling to the interior. However, the recommended method (of turning Lines into FilledCurves), i.e. by doing something like

ParametricPlot[
  {Cos[t] + 2 Cos[2 t], Sin[t] - 2 Sin[2 t]}
  , {t, 0, 2 π}
  , Frame -> True
  ] /. {Line[pts_] :> {FilledCurve[{Line[pts]}]}}

is unsatisfactory, since, as the documentation puts it,

Filled curves can be non-convex and intersect themselves. Self-intersecting curves are filled according to an even-odd rule that alternates between filling and not at each crossing.

This puts a big hole in the middle of my figure that I would also like to fill:

Mathematica graphics

How can I control the filling in that hole?

$\endgroup$
  • $\begingroup$ ParametricPlot[ r {Cos[t] + 2 Cos[2 t], Sin[t] - 2 Sin[2 t]}, {t, 0, 2 Pi}, {r, 0, 1}, Frame -> True] $\endgroup$ – Bob Hanlon Jun 5 '17 at 0:43
  • $\begingroup$ @Bob That's nowhere near sufficient - try e.g. changing the weight between the two components. $\endgroup$ – Emilio Pisanty Jun 5 '17 at 0:49
  • $\begingroup$ Related: (9406), (11517) $\endgroup$ – Mr.Wizard Jun 5 '17 at 0:52
  • 2
    $\begingroup$ That Mathematica does not have an option to disable this behavior is a pretty significant limitation compared to, say, SVG. $\endgroup$ – Rahul Jun 5 '17 at 1:22
2
$\begingroup$
pp = ParametricPlot[{Cos[t] + 2 Cos[2 t], Sin[t] - 2 Sin[2 t]}, {t, 0, 2 π} , 
        Frame -> True ] /. {Line[pts_] :> {FilledCurve[Line@pts]}};

bdg = BoundaryDiscretizeGraphics[pp[[1]], Frame->True]

Mathematica graphics

 BoundaryDiscretizeGraphics[pp[[1]], Frame->True, 
   MeshCellStyle -> {{1, All} -> Directive[Thick, Blue], {2} -> Yellow}]

Mathematica graphics

Or, use bdg in RegionPlot (thanks: @Mr.Wizard):

 RegionPlot @ bdg

Mathematica graphics

Note: In version 11, bdg = BoundaryDiscretizeGraphics @@ pp also works.

$\endgroup$
  • $\begingroup$ In v10.1 I need bdg = BoundaryDiscretizeGraphics @@ pp[[1]]; -- if that doesn't break code in other versions you might make that change. $\endgroup$ – Mr.Wizard Jun 5 '17 at 0:48
  • $\begingroup$ That's some pretty interesting tooling. $\endgroup$ – Emilio Pisanty Jun 5 '17 at 0:49
  • $\begingroup$ @Mr.Wizard, i made the change, $\endgroup$ – kglr Jun 5 '17 at 0:54
  • $\begingroup$ Thanks. Depending on the OP's needs RegionPlot[bdg] may be sufficient and significantly cleaner. $\endgroup$ – Mr.Wizard Jun 5 '17 at 1:00
  • $\begingroup$ @Mr.Wizard, thank you again. Added the RegionPlot alternative. $\endgroup$ – kglr Jun 5 '17 at 1:05
0
$\begingroup$

In:

xss = Table[{Cos[t] + 2 Cos[2 t] + 2, Sin[t] - 2 Sin[2 t]}, {t, 0, 
    2 \[Pi], 1/100}];
regionPlot[xss_] := ListLinePlot[
  xss, 
  Filling -> {Axis}, 
  FillingStyle -> LightBlue, 
  AspectRatio -> 1,
   Frame -> True, 
  Axes -> False,
   PlotStyle -> Transparent]
regionPlot@xss   

Out:

Mathematica graphics

$\endgroup$
  • $\begingroup$ Some notes: my region need not be centered at the origin, and I would like to explicitly avoid double-filling. $\endgroup$ – Emilio Pisanty Jun 4 '17 at 20:09

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.