4
$\begingroup$

As a continuation of this question, writing:

a = {x, 0};

b = 1.54;

f[x_] = Piecewise[{{a, x >= 1.38}, 
                   {{x, 0.27 (y - 1) (x - 1.38)}, 1.27 <= x < 1.38}, 
                   {{x, 0.48 (y - 1) (x - 1.33)}, True}}];

Normal@ParametricPlot[f[x], {x, 0, b}, {y, 0, 1}, 
                      MeshFunctions -> {#4 &, #4 &}, Mesh -> {{0}, {1}},
                      MeshStyle -> {Directive[Thickness[0.005], Green],
                      Directive[Thickness[0.005], Black]}, 
                      Exclusions -> None, 
                      PlotRange -> All, 
                      PlotStyle -> Green
                     ] /. p : {{__Polygon} ..} :> Graphics`PolygonUtils`PolygonCombine[p]

I get a correct output:

enter image description here

and the same, for example, for a = {x (1 - y) + x y, 0} and b = 2.30.

On the other hand, if I use a = {x, 0} and b = 1.53 or a = {x (1 - y) + x y, 0} and b = 2.40 I get:

enter image description here

which is clearly problematic. How do I combine the polygons in this case?


In response to Carl Woll:

g[x_] = Piecewise[{{{x, -0.12 x (x - 3.99) (y - 1)}, 2.61 <= x <= 3.00}, 
                   {{x, -0.24 x (x - 3.30) (y - 1)}, True}}];

Normal@ParametricPlot[g[x], {x, 0, 3}, {y, 0, 1}, 
                      MeshFunctions -> {#4 &, #4 &}, Mesh -> {{0}, {1}},
                      MeshStyle -> {Directive[Thickness[0.005], Green],
                      Directive[Thickness[0.005], Black]}, 
                      Exclusions -> None, 
                      PlotRange -> All, 
                      PlotStyle -> Green
                     ] /. p : {__Polygon} :> Graphics`PolygonUtils`PolygonCombine[p]

enter image description here

$\endgroup$
  • $\begingroup$ In your other example, use p:{__Polygon} :> Graphics`PolygonUtils`PolygonCombine[p] $\endgroup$ – Carl Woll Sep 3 '18 at 18:22
  • $\begingroup$ @CarlWoll: Thank you! In fact, the example shown works, but in the general case no, as shown in the second example. I begin to think that Graphics`PolygonUtils`PolygonCombine involves more problems than benefits (i.e. avoiding tessellation when exporting to pdf). $\endgroup$ – TeM Sep 3 '18 at 19:08
  • $\begingroup$ Side info: If you want to use inline code that contains backticks, simply use two backticks at the beginning and the end. If your code ends in a backtick, don't forget to put a whitespace between this trailing backtick and the two closing backticks. $\endgroup$ – halirutan Sep 6 '18 at 8:50
8
+200
$\begingroup$

Maybe you can use ParametricRegion instead of ParametricPlot. For instance:

reg = ParametricRegion[
    {
    x,
    Piecewise[
        {
        {-.12x(x-3.99)(y-1),2.61<=x<=3.00}
        },
        -.24x(x-3.30)(y-1)
    ]
    },
    {{x,0,3},{y,0,1}}
];

mesh = DiscretizeRegion[reg]

enter image description here

You can use a different undocumented internal function to combine the simplices in the MeshRegion:

simple = Region`Mesh`Simplify2DMesh @ mesh

enter image description here

You can use MeshPrimitives to extract the Polygon:

polygon = MeshPrimitives[simple, 2]

{Polygon[{{1.4985, 0.}, {1.42298, 0.}, {1.34747, 0.}, {1.27195, 1.37468*10^-16}, {1.19643, 1.34121*10^-16}, {1.12092, 0.}, {1.0454, 0.}, {0.969883, 0.}, {0.894367, -5.7328*10^-17}, {0.822559, -5.4299*10^-17}, {0.750751, 0.}, {0.678943, 0.}, {0.607134, 8.71267*10^-17}, {0.531618, 0.}, {0.456102, 0.}, {0.380585, 0.}, {0.305069, 0.}, {0.229552, 0.}, {0.154036, 0.}, {0.0785194, 0.}, {0.0407612, 0.}, {0.0218821, 2.63813*10^-19}, {0.0124426, 3.95719*10^-19}, {0.00772278, 4.61672*10^-19}, {0.003003, 5.27626*10^-19}, {0., 0.}, {0.003003, -0.00237621}, {0.0127835, -0.0100164}, {0.022564, -0.0176567}, {0.042125, -0.0329371}, {0.081247, -0.0627634}, {0.159491, -0.120212}, {0.237735, -0.174722}, {0.315979, -0.226293}, {0.394223, -0.274926}, {0.472467, -0.32062}, {0.550711, -0.363375}, {0.628955, -0.403192}, {0.705656, -0.439372}, {0.782358, -0.472727}, {0.859059, -0.503259}, {0.93576, -0.530967}, {1.00938, -0.554904}, {1.08299, -0.57624}, {1.15661, -0.594975}, {1.23022, -0.611109}, {1.29767, -0.623607}, {1.36511, -0.633921}, {1.43256, -0.642052}, {1.5, -0.648}, {1.56744, -0.651764}, {1.63489, -0.653345}, {1.70233, -0.652743}, {1.76978, -0.649957}, {1.84339, -0.644424}, {1.91701, -0.63629}, {1.99062, -0.625554}, {2.06424, -0.612217}, {2.14094, -0.595554}, {2.21764, -0.576068}, {2.29434, -0.553757}, {2.37104, -0.528623}, {2.44929, -0.500073}, {2.52753, -0.468585}, {2.60578, -0.434158}, {2.68402, -0.420633}, {2.76226, -0.40696}, {2.84051, -0.391817}, {2.91875, -0.375205}, {2.95787, -0.366348}, {2.97744, -0.361735}, {2.997, -0.357123}, {3., -0.356043}, {3., -0.351396}, {3., -0.346748}, {3., -0.337452}, {3., -0.318862}, {3., -0.300271}, {3., -0.28168}, {3., -0.245232}, {3., -0.227741}, {3., -0.21025}, {3., -0.1782}, {3., -0.162175}, {3., -0.14615}, {3., -0.128659}, {3., -0.111168}, {3., -0.0929441}, {3., -0.0747199}, {3., -0.0561291}, {3., -0.0375383}, {3., -0.0189475}, {3., -0.00965215}, {3., -0.00500445}, {3., -0.000356757}, {2.997, 0.}, {2.97807, 0.}, {2.95914, 0.}, {2.92129, 0.}, {2.84559, 0.}, {2.76988, 0.}, {2.69418, -4.65117*10^-17}, {2.61848, -4.78458*10^-17}, {2.54277, -5.13045*10^-17}, {2.46707, -1.09507*10^-16}, {2.39136, -1.15794*10^-16}, {2.31956, -6.05967*10^-17}, {2.24775, 0.}, {2.17594, 0.}, {2.10413, 1.34094*10^-16}, {2.02843, 1.37452*10^-16}, {1.95272, 1.402*10^-16}, {1.87702, 1.42337*10^-16}, {1.80131, 1.43864*10^-16}, {1.72561, 1.44779*10^-16}, {1.64991, 1.45084*10^-16}, {1.5742, 1.44778*10^-16}}]}

(it is possible to simplify this Polygon further if desired, as there are many collinear line segments)

You can include the above polygon in your ParametricPlot with Epilog:

ParametricPlot[
    g[x],
    {x,0,3},
    {y,0,1},
    MeshFunctions->{#4&,#4&},
    Mesh->{{0},{1}},
    MeshStyle -> {
        Directive[Thickness[0.005], Green],
        Directive[Thickness[0.005], Black]
    },
    Exclusions->None,
    PlotRange->All,
    Epilog -> {LightGreen, polygon}
]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you so much, fantastic! $\endgroup$ – TeM Sep 11 '18 at 18:18

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.