This is a bit of a two part question about optimizing some 3D plotting - it's pretty straightforward but after a while struggling with it I haven't made much headway. Assume some list of 3D points, i.e. pts = {{1,1,0},{1,1,0.1},{1,1,0.2}, ... ,{1,1,1}}
. I want to
a) plot those points in 3D space with a color gradient such as ColorData["SunsetColors"]
where the gradient is based on the index of the point in the list, rather than the value of the point. I have figured out a hacky way to do this, but I think it is probably far from optimal:
Graphics3D[{Thickness[0.005],
Line[pts,
VertexColors -> (ColorData["SunsetColors"][#/Length[pts]] & /@
Range[Length[pts]])]}, Background -> White]
I have tried working with ListPointPlot3D
but could not get the color gradient to work out. While this implementation technically works, its clunkiness makes it slow, which causes problems for part b), which is
b) Ideally I want to animate the trajectory of these points. The natural thing to do, building off the hacky solution to part a) is:
Animate[Graphics3D[{Thickness[0.005],
Line[pts[[1 ;; t]],
VertexColors -> (ColorData["SunsetColors"][#/Length[pts]] & /@
Range[Length[pts]])]}], {t, 1, Length[pts], 1}]
However, I find in practice that the animation does not look very smooth at all, even though the step size is 1, and can get very slow with a large number of points (typical trajectories can be multi-thousands). I'm basically wondering if there is cleaner solution to these problems, both the plotting with a color gradient, and the subsequent animation - ideally while still keeping the points connected like with Line[]
. Any help would be appreciated.