Colorize mesh according to the nodepoint colors
Do you mean something like this?
R = DelaunayMesh[p];
Graphics[
GraphicsComplex[
MeshCoordinates[R],
MeshCells[R, 2, "Multicells" -> True],
VertexColors -> c
]
]
Edit
Getting colorgradients on the edges only seems to be somewhat trickier as VertexCoordinate
for Line
objects in a GraphicsComplex
does not work. A workaround could be this:
elist = Flatten[MeshCells[R, 1, "Multicells" -> True][[1, 1]]];
Graphics[
Line[
Partition[MeshCoordinates[R][[elist]], 2],
VertexColors -> Partition[c[[elist]], 2]
]
]
SeedRandom[1]
p = RandomReal[{0, 1}, {10, 2}];
c = Map[Hue[#] &, RandomReal[{0, 1}, 10]];
1. Post-process MeshPrimitives
to add VertexColors
:
rule = pr : (_Polygon | _Line | _Point) :>
Append[pr, VertexColors ->
AssociationThread[p, c] /@ First[pr /. Point[x_] :> Point[{x}]]]
Row[Graphics[{AbsoluteThickness[5], AbsolutePointSize[12],
MeshPrimitives[DelaunayMesh[p], #] /. rule,
AbsoluteThickness[3], Black, Circle[#, Offset[6]] & /@ p},
ImageSize -> 300, PlotLabel -> Style[#, 16, Black]] & /@
{0 | 1, 0 | 2, 0 | 1 | 2}, Spacer[5]]
2. Use the option MeshCellShapeFunction
with desired styles/primitives for vertices, edges and faces:
Row[{DelaunayMesh[p, ImageSize -> 400,
MeshCellStyle -> White,
MeshCellShapeFunction ->
{{0, All} -> ({c[[#3[[1, 1]]]], Disk[#, Offset[7]]} &),
{1, All} -> ({AbsoluteThickness[7], CapForm["Round"],
Line[#, VertexColors -> c[[#3[[1, 1]]]]]} &),
{2, All} -> None}],
DelaunayMesh[p, ImageSize -> 400,
MeshCellStyle -> White,
MeshCellShapeFunction ->
{{0, All} -> ({c[[#3[[1, 1]]]], Disk[#, Offset[7]]} &),
{1, All} -> None,
{2, All} -> ({EdgeForm[Gray],
Polygon[#, VertexColors -> c[[#3[[1, 1]]]]]} &)}]}]
If you're interested in doing this with 3D mesh objects (as I was) the following works in Mathematica 12.1:
mesh = BoundaryDiscretizeRegion[Ball[{0, 0, 0}, 1],
MaxCellMeasure -> {"Length" -> 1}, PrecisionGoal -> 0.01] (* or any mesh object *)
vertexscalar = RandomReal[{0, 1}, Length[MeshCoordinates[mesh]]]
Graphics3D[
GraphicsComplex[MeshCoordinates[mesh],
Polygon[MeshCells[mesh, 2][[All, 1]]],
VertexColors -> ColorData["DarkRainbow"] /@ Rescale[vertexscalar]]]