2
$\begingroup$

I have these two lists

xyz={{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 
  1, -1}, {-1, -1, 1}, {-1, -1, -1}}

color={GrayLevel[0.5], GrayLevel[0.5], RGBColor[0, 1, 0], GrayLevel[0.5], 
 GrayLevel[0.5], GrayLevel[0.5], GrayLevel[0.5], RGBColor[0, 1, 0]}

I need to use this function Graphics3D[{*Green*, Sphere[]}] to plot each sphere with coordinates from xyz list and colour from col list.

by applying MapThread[].

$\endgroup$
  • $\begingroup$ Graphics3D[{dfhgkjdfhg, MapThread[{#1, Sphere[#2]} &, {col, xyz}]}] $\endgroup$ – Emamof Jun 28 '12 at 21:59
  • $\begingroup$ Just an added detail: the colors will look more natural if you add Lighting -> "Neutral" at the end of Graphics (since I assume the true colors are important to you). $\endgroup$ – Jens Jun 29 '12 at 16:07
5
$\begingroup$

You can do the following:

Graphics3D[MapThread[{#1, Sphere@#2} &, {color, xyz}]]

enter image description here

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Of course, if you want to avoid the hassle of MapThread[]: {color, Sphere /@ xyz} // Transpose // Graphics3D $\endgroup$ – J. M.'s technical difficulties Jun 29 '12 at 0:56
  • $\begingroup$ Got it, Thanks for care. $\endgroup$ – Emamof Jun 29 '12 at 3:53
2
$\begingroup$

Instead of MapThread you could use Map (/@) and Thread.

Graphics3D @ Thread @ {color, Sphere /@ xyz}

Or Map and Riffle:

Graphics3D @ Riffle[color, Sphere /@ xyz]

Mathematica graphics

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Why the down-vote? $\endgroup$ – Mr.Wizard Jun 29 '12 at 13:02

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.