5
$\begingroup$

If I have a list of points {x,y,z} and for each point an rgb colour, e.g.: points={{0,0,0,1,0,0}, {1,0,0,0,1,0}, {1,1,1,0,0,1}} how can I plot the surface covering the given points (ListPlot3D) and colour it with blends of the individual colours?

In the above example, I expect a triangle with a red, green and blue corner and in-between blends of the three colours depending on the distance to the corners.

$\endgroup$
6
$\begingroup$

Use the option VertexColors with ListPlot3D:

ListPlot3D[points[[All, ;; 3]],  
 Mesh -> None, BoxRatios -> 1, 
 Lighting -> "Neutral", 
 VertexColors -> (RGBColor @@@ points[[All, 4 ;;]])]

enter image description here

SeedRandom[1]
points2 = RandomReal[1, {20, 6}]; 

ListPlot3D[points2[[All, ;; 3]], 
 Mesh -> None, BoxRatios -> 1, Lighting -> "Neutral", 
 VertexColors -> (RGBColor @@@ points2[[All, 4 ;;]])]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ This is the right answer. $\endgroup$ – Szabolcs Dec 13 '19 at 21:47
3
$\begingroup$

Here's a starting point, which you can customize to your needs:

colourListPlot3D[data_, opt : OptionsPattern[]] := 
 Module[{pts2d = data[[All, 1 ;; 2]]},
  Graphics3D[
   GraphicsComplex[data[[All, 1 ;; 3]],
    MeshCells[DelaunayMesh[pts2d], 2],
    VertexColors -> data[[All, 4]]
    ],
   opt
   ]
  ]

I am assuming an input in the format data = {{x1, y1, z1, color1}, ...}.

points = {{0, 0, 0, 1, 0, 0}, {1, 0, 0, 0, 1, 0}, {1, 1, 1, 0, 0, 1}};

data = {#1, #2, #3, RGBColor[##4]} & @@@ points;

colourListPlot3D[data]

enter image description here

$\endgroup$
  • $\begingroup$ Let me know if you need more explanation on how this works. $\endgroup$ – Szabolcs Dec 13 '19 at 14:15

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.