3
$\begingroup$

I have a list of points in the form of

data = {{x1, y1, z1}, {x2, y2, z2}, ......, {xn, yn, zn}}

and I can draw a 3D curve using the data using the command

Graphics3D[{Thickness[0.01], Line[data]}, Axes -> True].

However, I would like to have the colour of the curve changing continuously using a colour map. Basically I want a result similar to what one can do with ParametricPlot3D. For instance,

ParametricPlot3D[{Cos[t], 0, Sin[t]}, {t, 0, 2 Pi}, 
  ColorFunction -> Function[{x, y, z, t}, ColorData["Rainbow"][t]]]

produces an output like below:

enter image description here

How can I do the same thing when I have the data as a list of points?

$\endgroup$
3
$\begingroup$

Here is one way:

pnts = N@Table[{Cos[t], 0, Sin[t], t}, {t, 0, 2 Pi, Pi/20}];
pnts[[All, -1]] = Rescale[pnts[[All, -1]]];
Graphics3D[{Thickness[0.01], 
  Map[{ColorData["Rainbow"][Mean[#[[All, -1]]]], Line[Most /@ #]} &, 
   Partition[pnts, 2, 1]]}]

enter image description here

$\endgroup$
2
$\begingroup$

My interpretation of "continuously changing colours" using CirclePoints , VertexColors and Hue

Graphics3D

ListAnimate@With[
  {
   n = 30
   },
  Table[
   Graphics3D[
    {Thick,
     Line[
      Append[#, First[#]] &[
       Prepend[0] /@ CirclePoints[n]
       ]
      , VertexColors -> RotateLeft[Array[Hue, n + 1, {0, 0.8}], k]
      ]
     }
    ],
   {k, n}
   ]]

enter image description here

ListPointPlot3D

ListAnimate@
 With[
  {n = 50},
  Table[
   ListPointPlot3D[
    List@*Prepend[0] /@ CirclePoints[n]
    , PlotStyle -> RotateLeft[Array[Hue, n + 1, {0, 0.8}], k]
    , BoxRatios -> {1, 1, 1}
    ]
   , {k, n}]
  ]

enter image description here

$\endgroup$

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.