5
$\begingroup$

Let's say I make a mesh from a collection of random points:

SeedRandom[1234]
points = RandomReal[1, {20, 2}];
mesh = VoronoiMesh[points]

original mesh

For the purposes of my question we can just make an automatic highlighting of each cell (I want the colors of each cell to be different):

HighlightMesh[mesh, Table[{2, {i}}, {i, 20}]]

color mesh

I want to be able to take the colored mesh and remove the edges between each "cell" so that it essentially goes from one color to the next. Of course, I could just color each edge the same color as a cell it is touching, but that seems to be inefficient, especially if there is a quick way to remove the edges. I can't seem to find a way to just make the edges non-existent in the drawing of the mesh. From what I have been looking up, it seems like there is a lot of undocumented things you can do with meshes, and even if something is documented it is difficult to find what you are looking for sometimes since the information of meshes in Mathematica is so extensive.

Thanks in advance.


UPDATE The answer so far works for the color mesh I posted, but what if my cells are darker in color? In this case changing the Opacity doesn't quite do the trick.

enter image description here

Opacity set to 0 for edges:

enter image description here

$\endgroup$
7
$\begingroup$

Use the MeshCellStyle option:

SeedRandom[1234]
points = RandomReal[1, {20, 2}];
mesh = VoronoiMesh[points, MeshCellStyle->{1->Opacity[0]}];

HighlightMesh[mesh, Table[{2, {i}}, {i, 20}]]

enter image description here

or:

SeedRandom[1234]
points = RandomReal[1, {20, 2}];
mesh = VoronoiMesh[points];

MeshRegion[
    HighlightMesh[mesh, Table[{2, {i}}, {i, 20}]],
    MeshCellStyle->{1->Opacity[0]}
]

enter image description here

Addendum

I think for gray scale images, the lines you are seeing are an antialiasing artefact. If you turn off antialiasing, the line color should be suppressed, but they will be very jagged:

HighlightMesh[
    mesh,
    Table[Style[{2,i}, GrayLevel[RandomReal[.5]]], {i, 20}],
    MeshCellStyle -> {1 -> Directive[Opacity[0], Antialiasing->False]}
]

enter image description here

$\endgroup$
  • $\begingroup$ What if the cells are darker in color (closer to black)? I might edit my example to use graylevels $\endgroup$ – Aaron Stevens Jan 31 at 17:39
  • $\begingroup$ @AaronStevens that shouldn't change anything. Carl just made the boundaries disappear. $\endgroup$ – b3m2a1 Jan 31 at 19:11
  • $\begingroup$ @b3m2a1 I edited the question to show an example with darker colors. You can still see light borders around the dark cells $\endgroup$ – Aaron Stevens Jan 31 at 20:01
  • $\begingroup$ Huh yeah I guess it is the antialiasing for the darker ones. The actual meshes I will be using have smaller cells, so maybe the jagged edges won't be as noticable. $\endgroup$ – Aaron Stevens Feb 1 at 2:29

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.