# How to draw the trajectory of a moving particle

I want to draw a 3D graph showing a nanoparticle movements in liquid environment. Basically,the code is like the followings. I used Table to generate the position coordinates instead of using the random movement position for simplicity here. My problem is I want to make the trajectory shown as connected lines instead of discrete points while maintain a rainbow-like color.

pts = Table[{t/100, (t/100)^1, (t/100)^2}, {t, 1, 100}];
pts1 = Table[{{t1/100, t1/100}, (t/100)^2}, {t1, 1, 100}, {t2, 1,100}];
Graphics3D[{Thickness[0.05], Hue[#], Point[#]} & /@ pts, BoxRatios -> {1, 1, 1}]


Perhaps VertexColors achieves what you're after?

Graphics3D[{Thickness[0.005], Line[#, VertexColors -> Hue /@ #]} &@ pts, BoxRatios -> {1, 1, 1}] If you want a "purer" rainbow, perhaps use just the first coordinate of the pts:

Graphics3D[{Thickness[0.005], Line[#, VertexColors -> Hue /@ #[[All, 1]]]} &@ pts,
BoxRatios -> {1, 1, 1}] In this case, the coordinates happen to go from 0 to 1. If not, you could use Rescale:

VertexColors -> Hue /@ Rescale[#[[All, 1]]]

• That's perfect. Thanks Sep 19, 2014 at 0:55
• @MYG You're welcome. Sep 19, 2014 at 0:56