Mathematica Asked by Mustafa Kösem on December 15, 2020
I want to colorize lines as a function of coordinates in 3D. Here is my code. In this graphic I used one color. My aim is using a color function based on 3d coordinates.
points = RandomReal[{0, 20}, {100, 3}]
graph = Graphics3D[{Hue[0.67, 0.6, 0.6], Line[points]},
PlotRange -> All, BoxRatios -> {1, 1, 1}, ImageSize -> 300]
You can use VertexColors
to color a line segment by blending the two colors associated with the two vertices:
SeedRandom[1]
points = RandomReal[{0, 20}, {100, 3}];
Graphics3D[{Thick, Line[points, VertexColors -> (Hue @@@ Rescale[points])]},
PlotRange -> All, BoxRatios -> {1, 1, 1}, ImageSize -> 300]
Alternatively, you can use BSplineFunction
+ ParametricPlot3D
with a color function that depends on the first 3 arguments:
ParametricPlot3D[BSplineFunction[points, SplineDegree -> 1][t], {t, 0, 1},
ColorFunction -> (Hue[#, #2, #3] &), BoxRatios -> {1, 1, 1},
ImageSize -> 300]
Correct answer by kglr on December 15, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP