1
$\begingroup$

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}]
$\endgroup$

1 Answer 1

3
$\begingroup$

Perhaps VertexColors achieves what you're after?

Graphics3D[{Thickness[0.005], Line[#, VertexColors -> Hue /@ #]} &@ pts, BoxRatios -> {1, 1, 1}]

Mathematica graphics

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}]

Mathematica graphics

In this case, the coordinates happen to go from 0 to 1. If not, you could use Rescale:

VertexColors -> Hue /@ Rescale[#[[All, 1]]]
$\endgroup$
2
  • $\begingroup$ That's perfect. Thanks $\endgroup$
    – BNHSX
    Sep 19, 2014 at 0:55
  • $\begingroup$ @MYG You're welcome. $\endgroup$
    – Michael E2
    Sep 19, 2014 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.