2
$\begingroup$

Given a set p of points (2D), each with a unique color c, I can mesh these points easily

p = RandomReal[{0, 1}, {10, 2}];
c = Map[Hue[#] &, RandomReal[{0, 1}, 10]]; 
Show[DelaunayMesh[p],Graphics[Graphics[MapThread[{PointSize[.05], #1, Point[#2]} &, {c, p}]]]]

enter image description here

My question:

How can I easily colorize the lines and/or triangles according to the neighboring node colors?

Thanks!

$\endgroup$
  • $\begingroup$ Can you clarify the rules? For instance, what color should the line between a blue and yellow dot be? How should a triangle face color be chosen, given the colors of its vertices? $\endgroup$ – MarcoB Mar 6 '19 at 18:52
  • $\begingroup$ @ MarcoB Along the line I would expect some blending. $\endgroup$ – Ulrich Neumann Mar 6 '19 at 18:55
5
$\begingroup$

Do you mean something like this?

R = DelaunayMesh[p];
Graphics[
 GraphicsComplex[
  MeshCoordinates[R],
  MeshCells[R, 2, "Multicells" -> True],
  VertexColors -> c
  ]
 ]

enter image description here

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]
  ]
 ]

enter image description here

$\endgroup$
  • $\begingroup$ Yes, that's it! Thank you very much $\endgroup$ – Ulrich Neumann Mar 6 '19 at 18:58
  • $\begingroup$ You're welcome, Ulrich. $\endgroup$ – Henrik Schumacher Mar 6 '19 at 19:02
  • $\begingroup$ @ Henrik Where can I find information about the option "Multicells" -> True? In MMA v11.0.1. it isn't known . $\endgroup$ – Ulrich Neumann Mar 6 '19 at 19:28
  • $\begingroup$ Nowhere. user21 once told me. Very useful. Even the syntax highlighter of version 11.3 but it might work in version 11.0.1 already. If not, you may use Polygon[MeshCells[R, 2][[All, 1]]] instead (but it unpacks arrays and therefore may be slower for large meshes). $\endgroup$ – Henrik Schumacher Mar 6 '19 at 19:35
  • $\begingroup$ Again thank you for your useful help! $\endgroup$ – Ulrich Neumann Mar 6 '19 at 19:39

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.