1
$\begingroup$

I would like to plot a Graphics3D object colored based on the value of some spatial function. For example to plot a triangle colored by the function cf I might start with:

testCorners = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
testTriangle = Triangle[testCorners];
cf [{x_, y_, z_}] = ColorData["NeonColors"][z];

I hope that there is a couple of lines, probably involving Graphics3D that will plot this triangle (or other, more complicated surfaces) colored with the function I have specified (or other more complicated functions of x, y, and z).

I can do fun stuff like color vertices and have Mathematica linearly interpolate over the faces.

Graphics3D[
 Append[PolyhedronData["Dodecahedron", "GraphicsComplex"], 
  VertexColors -> ColorData["NeonColors"] /@ RandomReal[{0, 1}, 20]]]

A dodecahedron with its vertices colored

It may be possible to use a similar method by transforming the surface into a GraphicsComplex object and then setting VertexTextureCoordinates appropriately and supplying a Texture to Graphics3D, but that seems quite complicated...

$\endgroup$

1 Answer 1

1
$\begingroup$
gc = PolyhedronData["Dodecahedron", "GraphicsComplex"];
minmax = MinMax @ N @ gc[[1, All, -1]]

Graphics3D[Append[gc, 
  VertexColors -> (ColorData[{"NeonColors", minmax}] /@ gc[[1, All, -1]])]]

enter image description here

Alternatively, use your cf with rescaled arguments:

Graphics3D[Append[gc, 
   VertexColors -> (cf /@ Transpose[Rescale /@ Transpose[First @ N @ gc]])]

same picture

Update: "but suppose I had a color function which was radially symmetric like Norm. The dodecahedron would be uniformly colored, even though the centers of each face should have a lower value."

texture = RadialGradientImage["NeonColors"];

Graphics3D[Normal[gc] /. Polygon[x_] :>
  {Texture @ texture,
   Polygon[x, VertexTextureCoordinates -> Rescale[CirclePoints @ Length @ x]]}]

enter image description here

Further examples:

SeedRandom[1]
polyhedra = RandomSample[PolyhedronData["Archimedean"], 12];

Graphics3D[Normal[PolyhedronData[#, "GraphicsComplex"]] /. 
     Polygon[x_] :> {Texture @ texture, 
       Polygon[x, 
        VertexTextureCoordinates -> Rescale[CirclePoints @ Length @ x]]}, 
    Lighting -> "Neutral"] & /@  polyhedra // Multicolumn[#, 4] &

enter image description here

$\endgroup$
4
  • $\begingroup$ This is useful but suppose I had a color function which was radially symmetric like Norm. The dodecahedron would be uniformly colored, even though the centers of each face should have a lower value. $\endgroup$
    – alessandro
    Oct 5, 2020 at 20:53
  • 1
    $\begingroup$ @alessandro, please see the update. $\endgroup$
    – kglr
    Oct 5, 2020 at 21:46
  • $\begingroup$ That looks spectacular, let me play with it for a second and I'll get back to you. $\endgroup$
    – alessandro
    Oct 5, 2020 at 21:53
  • $\begingroup$ This doesn't let me specify an arbitrary function. It just maps the same image on to each face. An texture for each face could be made I suppose though... $\endgroup$
    – alessandro
    Oct 5, 2020 at 23:42

Your Answer

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

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