Mathematica Asked on January 19, 2021
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]]]
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…
gc = PolyhedronData["Dodecahedron", "GraphicsComplex"];
minmax = MinMax @ N @ gc[[1, All, -1]]
Graphics3D[Append[gc,
VertexColors -> (ColorData[{"NeonColors", minmax}] /@ gc[[1, All, -1]])]]
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]]}]
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] &
Answered by kglr on January 19, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP