4
$\begingroup$
Show[
 Graphics[Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}},VertexColors -> {Opacity[0, Red], Opacity[1, Red], Opacity[1, Red],Opacity[0, Red]}]], 
 Graphics[Circle[{0.5, 0.5}, 0.2]]
 ]

Show[
 Graphics[{Red, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}],
 Graphics[Circle[{0.5, 0.5}, 0.2]]
 ]

Where the circle in first one looks bad smoothness. Any method to fix this? enter image description here

$\endgroup$
3
  • $\begingroup$ related: Antialiasing of horizontal lines but Antialising trick doesn't work in this case (v9 and v11.3) $\endgroup$
    – kglr
    Jul 28, 2018 at 6:15
  • $\begingroup$ Just as info: This is not happening in my copy of version 11.3 for macOS. $\endgroup$ Jul 28, 2018 at 8:40
  • $\begingroup$ Related: (7416) $\endgroup$
    – Mr.Wizard
    Jul 29, 2018 at 3:25

3 Answers 3

2
$\begingroup$

How about:

Show[
    Graphics[
        Polygon[
            {{0,0},{1,0},{1,1},{0,1}},
            VertexColors->{Opacity[0,Red],Opacity[1,Red],Opacity[1,Red],Opacity[0,Red]}
        ]
    ],
    Graphics[{Antialiasing->True,Circle[{0.5,0.5},0.2]}]
]

enter image description here

$\endgroup$
2
$\begingroup$

Two workarounds:

Graphics[{Raster[Table[{1, 0, 0, y}, {x, 0, 1, 1/100}, {y, 0, 1, 
     1/100}], {ImageScaled[{0, 0}], ImageScaled[{1, 1}]}], 
  Circle[{.5, .5}, .2]}, PlotRange -> {{0, 1}, {0, 1}}]

enter image description here

Overlay[{Graphics[Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, 
  VertexColors -> {Opacity[0, Red], Opacity[1, Red], Opacity[1, Red], Opacity[0, Red]}]], 
  Graphics[Circle[{0.5, 0.5}, 0.2], PlotRange -> {{0, 1}, {0, 1}}]}]

enter image description here

$\endgroup$
2
$\begingroup$

As to the "why": because once you include a Polygon with VertexColors, the graphics will be rendered by the GPU (the same as 3D graphics). This means limited support for anti-aliasing which is going to be GPU-dependent.

You can turn on anti-aliasing for such graphics in the preferences, if your GPU supports it.

enter image description here

$\endgroup$

Your Answer

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

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