3
$\begingroup$

Is there any easy way to cut a thick curve in half lengthwise? Example: suppose I have the cardioid shown in the figure below, is there a way to delete either the inner or the outer portion of the curve along the dashed line? Thanks for reading!!

enter image description here

Edit: code used to generate plot.

g = ParametricPlot[{(1 + Cos[t]) Cos[t], (1 + Cos[t]) Sin[t]}, {t, 0, 
2 Pi}, PlotRange -> {{-0.5, 2.2}, {-1.5, 1.5}}, 
PlotStyle -> {Thickness[0.06]}];

h = ParametricPlot[{(1 + Cos[t]) Cos[t], (1 + Cos[t]) Sin[t]}, {t, 0, 
2 Pi}, PlotRange -> {{-0.5, 2.2}, {-1.5, 1.5}}, 
PlotStyle -> {Thickness[0.0035], White, Dashed}];

Show[g, h]
$\endgroup$
6
  • 2
    $\begingroup$ If you don't need the inside to be transparent, what I do is to draw the curve again filled with white, leaving only the outer half showing. $\endgroup$
    – user484
    Dec 23, 2014 at 14:45
  • $\begingroup$ Thanks, but how does that help, Rahul? Mathematica always centers the second curve along the middle (the dashed line in my pic) of the orginal curve, so your solution would only leave two blue curves separated by the width of the white curve. Whereas what I want is a single curve on one side of the dashed line. In other words: if you imagine the thick blue cardioid curve to be a road, I only want the left or the right lane. $\endgroup$ Dec 23, 2014 at 16:04
  • $\begingroup$ This has been asked before, but I can't find the original. Anyone? $\endgroup$ Dec 23, 2014 at 16:56
  • 2
    $\begingroup$ In the answers to 28202, the normal to the curve was extended on both side. Adapt to extend on one side only. Post your answer here if you figure it out (unless the community thinks it's duplicate). If you can't figure it out, let us know. Some go-getter will no doubt figure it out in the meantime. $\endgroup$
    – Michael E2
    Dec 23, 2014 at 17:29
  • 1
    $\begingroup$ @Kim By "filled with white" I meant colouring the interior of the cardioid with white, not the perimeter. In the road metaphor this covers the inside lane as well as the traffic island in the middle. I believe that's what the first part of Algohi's answer does. $\endgroup$
    – user484
    Dec 23, 2014 at 19:09

2 Answers 2

5
$\begingroup$

Since you said "Or", I will do the inner one. you can do it like this:

p1 = ParametricPlot[
   r {(1 + Cos[t]) Cos[t], (1 + Cos[t]) Sin[t]}, {t, 0, 2 Pi}, {r, 0, 
    1}, PlotRange -> All, Frame -> False, 
   PlotStyle -> {White, Opacity[1]}];
Show[g, h, p1]

enter image description here

For the outer one "Also can be used in general for inner and outer" you can use:

p1 = ParametricPlot[{1 - r + r (1 + Cos[t]) Cos[t], 
    r (1 + Cos[t]) Sin[t]}, {t, 0, 2 Pi}, {r, 1, 2}, PlotRange -> All,
    Frame -> False, PlotStyle -> {White, Opacity[1]}];
Show[g, h, p1]

enter image description here

$\endgroup$
4
$\begingroup$

If you really need a Graphics object that represents a "sliced" version of the boundary curve (instead of just hiding one half of the line as in Algohi's solution which I also upvoted because it's easier), then you can achieve that as follows:

g = ParametricPlot[{(1 + Cos[t]) Cos[t], (1 + Cos[t]) Sin[t]}, {t, 0, 
    2 Pi}, PlotRange -> {{-0.5, 2.2}, {-1.5, 1.5}}, 
   PlotStyle -> {Thickness[0.06]}];

h = ParametricPlot[{(1 + Cos[t]) Cos[t], (1 + Cos[t]) Sin[t]}, {t, 0, 
    2 Pi}, PlotRange -> {{-0.5, 2.2}, {-1.5, 1.5}}, 
   PlotStyle -> {Thickness[0.0035], White, Dashed}];

pts = Polygon[First[Cases[g, Line[x_] :> x, Infinity]]];

rdf = SignedRegionDistance[pts];

rp = With[{thickness = .1},
   RegionPlot[
    0 < rdf[{x, y}] < thickness, {x, -.7, 2.5}, {y, -1.6, 1.6}, 
    PlotStyle -> Darker[Blue], BoundaryStyle -> None, 
    PlotPoints -> 50]
   ];

Show[rp, h, Background -> Lighter[Orange]]

cardioid

After reproducing the definitions of g and h from the question, I extract the boundary points of the parametric curve from g and use them to define a geometric Region by turning them into a Polygon for which we can then compute the signed distance in the function rdf. The function SignedRegionDistance yields 0 when you're on the line defined by the original plot g and h, and has a positive value outside that region. This can be used to impose a desired thickness in the RegionPlot that I store in the result rp, which then consists of a polygon that describes the desired shape with the desired thickness, but is outlined only in the outward direction.

To show that the graphics object is indeed the desired longitudinal slice, I superimpose it on the dashed parametric curve h with an added background that proves that nothing was hidden by overlying opaque regions.

The quality of the polygon can be changed by adjusting the PlotPoints option in RegionPlot. If necessary, you can also extract the polygon from the RegionPlot by doing First@Normal@rp.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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